0

对于我正在编写的一个简单的应用程序,logcat 会发送很多GC_FOR_MALLOC这样的消息:

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

该应用程序并不多,仅使用 Apache HttpClient 4.X 通过 https 加载两个 HTML 文档。我已经定义了android:largeHeap="true",但它没有帮助。

从我读到的消息中,我有 50% 的可用内存,但 GC 还是被迫运行。你知道为什么会发生这种情况,以及如何解决这个问题吗?谢谢。

4

1 回答 1

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.

于 2012-11-12T00:13:33.787 回答