GC_FOR_ALLOC更“严重”吗?在调查内存使用情况时? [英] Is GC_FOR_ALLOC more "serious" when investigating memory usage?
问题描述
我目前正在用我的Android应用程序调查垃圾收集问题,我很想知道GC_FOR_ALLOC是否指示比其他GC消息(如GC_CONCURRENT)更大的问题。
据我了解,GC_CONCURRENT正在做垃圾回收器应该做的事情。堆已经达到了一个特定的限制,最好去清理内存。
GC_FOR_ALLOC向我建议更严重的事情发生,如果我试图创建一个对象,并且没有内存留下来做。
GC消息有优先级或严重性级别吗?
GC_CONCURRENT
更严重,因为 GC_FOR_ALLOC
意味着没有足够的可用内存来完成分配请求,所以需要垃圾回收,而 GC_CONCURRENT
只是意味着GC感觉就像跑步一样,通常是因为分配后可用内存的数量低于某个阈值。 A GC_FOR_ALLOC $ c然而,$ c>本身并不是您的应用程序中存在问题的标志:
是不可避免的。而且分配内存的速度比并发GC可以释放内存的速度更快。
GC_FOR_ALLOC
。在这种情况下, GC_FOR_ALLOC
是完全正常的。
Android上更严重的GC类型是 GC_BEFORE_OOM
,当分配请求在 GC_FOR_ALLOC
之后失败并且应用程序堆增长得如此大被允许。当发生这种情况时,作为最后的手段,Dalvik将尝试释放SoftReferences,然后再进行最后的内存分配尝试,并且该失败将抛出OutOfMemory异常。
如果你想看看这个逻辑的代码,它在 tryMalloc()中。 p =平台/ dalvik.git; A =斑点; F = VM /分配/ Heap.cpp; H = 9eee817e5e5cc1115041c5548214292a7f6e1090; HB = HEAD> dalvik.git / VM /分配/ Heap.cpp
无论如何,如果您不介意,我怀疑查看logcat输出是调试垃圾回收问题的最有效方法。我不知道你有什么具体问题,但是你有没有看过DDMS中的Allocation Tracker等工具,并借助 hprof-conv
来分析堆转储。工具? (请参阅 http://android-developers.blogspot.se/2011/03/内存分析为android.html 例如开始。)
I'm currently investigating garbage collection problems with my Android app, and I'm curious to know if GC_FOR_ALLOC is indicative of a bigger problem than other GC messages, such as GC_CONCURRENT.
From my understanding, GC_CONCURRENT is doing what the garbage collector should do. The heap has reached a particular limit, better go clean up memory.
GC_FOR_ALLOC suggests to me something more serious is happening if I'm trying to create an object and there's no memory left to do it.
Is there a priority or "seriousness" level for the GC messages?
In a sense, GC_FOR_ALLOC
is more serious than GC_CONCURRENT
, because GC_FOR_ALLOC
means there were not enough free memory to fulfill an allocation request, so a garbage collection was necessary, whereas GC_CONCURRENT
just means that the GC felt like running, typically because the amount of free memory became lower than a certain threshold after an allocation.
A GC_FOR_ALLOC
is by itself not a sign of a problem in your application however:
- Android applications start with a small heap which grows (up to a point) when applications require more and more memory, and a
GC_FOR_ALLOC
is done before increasing the size of the heap. In this caseGC_FOR_ALLOC
is perfectly normal. - If you allocate memory faster than the concurrent GC has time to free it up,
GC_FOR_ALLOC
is inevitable. And there's nothing inherently wrong with allocating memory faster than the concurrent GC can free up memory.
A more serious type of GC on Android is GC_BEFORE_OOM
, which is performed when an allocation request fails even after GC_FOR_ALLOC
and when the application heap has grown as big as it is allowed to be. When this happen, as a last resort, Dalvik will try to release SoftReferences as well, before doing a final attempt at allocating memory and if that fails throw an OutOfMemory exception.
If you're curious to look at the code for this logic, it is in tryMalloc()
in dalvik.git/vm/alloc/Heap.cpp
Anyway, if you don't mind, I doubt that looking at logcat output is the most efficient way to debug your garbage collection problems. I don't know what specific problem you are having, but have you looked into tools such as the Allocation Tracker in DDMS and analyzing heap dumps with the help of the hprof-conv
tool? (See http://android-developers.blogspot.se/2011/03/memory-analysis-for-android.html for example to get started.)
这篇关于GC_FOR_ALLOC更“严重”吗?在调查内存使用情况时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!