简体   繁体   中英

LogCat spams GC_FOR_MALLOC but only 50% of memory is used

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM