0

For a simple app I am writing, logcat spams lots of GC_FOR_MALLOC messages like these:

D/dalvikvm(10236): GC_FOR_MALLOC freed 224K, 51% free 3290K/6599K, external 0K/0K, paused 21ms
D/dalvikvm(10236): GC_FOR_MALLOC freed 290K, 50% free 3323K/6599K, external 0K/0K, paused 33ms
D/dalvikvm(10236): GC_FOR_MALLOC freed 229K, 50% free 3325K/6599K, external 0K/0K, paused 24ms

The app does not much, only loads two HTML documents via https using Apache HttpClient 4.X. I already defined android:largeHeap="true", but it is not helping.

From the message I read that I have 50% memory free, but the GC is forced to run anyway. Do you know why this occurs, and how this can be fixed? Thanks.

opatut
  • 6,200
  • 5
  • 28
  • 36
  • normal for me, it doesnt cause a problem at all. I think it just shows up when you are freeing memory. Nothing to worry about? – IAmGroot Nov 11 '12 at 20:29
  • Well I worry about it because it takes a lot of time to initialize my app (there are about 500 such warnings, each takes 20 ms, which takes 10 seconds to load my app). – opatut Nov 11 '12 at 20:56
  • I am under the impression that they arnt warnings, just information output. What ever is using the processor so much, causing these info logs is the problem. Or area to increase in speed. – IAmGroot Nov 11 '12 at 21:32

1 Answers1

2

Probably there is something wrong with your code. I'm going to give a generic answer, as no code is provided.

If you have 500 messages informing that about 250K was released in each one, means that your code has allocated/released a total of 125MB.

This shouldn't happen for general html pages, that usualy doesn't require this amount of memory.

You need to identify which objects are being repeatedly created/released by your application and try to reuse them instead of creating new ones.

In Eclipse you can use DDMS tab for that. Select your process, go for the Allocation Tracker and press Start Tracking, to get the objects that are being allocated.

Regards.

Luis
  • 11,772
  • 3
  • 23
  • 35
  • I think I might have found the error using `DDMS`. Can you help me, how would you better read all content from an input stream than using a BufferedReader? `String s1, s = ""; while ((s1 = bufferedReader.readLine()) != null) s += s1 + "\n";` This is how I read the response... – opatut Nov 12 '12 at 09:41
  • Well, using the content length of the response and the `inputStream.read()` method directly removed all the allocations and warnings. Sadly, it still takes a long time, but I guess this issue is resolved then. Thanks. – opatut Nov 12 '12 at 10:00
  • Now it is finally solved using the `Scanner` util, as seen [here](http://stackoverflow.com/a/5445161/402551). – opatut Nov 12 '12 at 10:16