Wednesday, 21 August 2013

Downloading large files in Android - too much gc?

Downloading large files in Android - too much gc?

I have a class that extends Thread.
In it, my run() method has a while loop:
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
input = new BufferedInputStream(urlConnection.getInputStream());
output = new FileOutputStream(localFile, true);
urlConnection.setReadTimeout(10000);
byte data[] = new byte[16384];
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
We are targeting ICS and above. When we are downloading, we see a lot of
Garbage Collection occuring in logcat. It seems like a trivial method, is
there something we're doing wrong here? We're only creating the data array
once.

No comments:

Post a Comment