[英]Android Garbage Collector behavior
Ok, I know there was a few similar questions, but I couldn't find nowhere pure facts about GC
in android. 好的,我知道有一些类似的问题,但是我在Android中找不到关于
GC
纯事实。
When system calls GC
? 系统何时调用
GC
?
What GC
in android counts as not needed? android中的什么
GC
算作不需要的?
Why GC
skips bitmaps? 为什么
GC
跳过位图?
Sample of code that shows how we can bypass GC
? 显示如何绕过
GC
的代码示例? (Object = null ?) (对象= null?)
What does GC
do with not needed object? GC
对不需要的对象有什么作用?
Other important facts... 其他重要事实...
** When system calls GC? **系统何时调用GC? What GC in android counts as not needed?
android中的什么GC算作不需要的? **
**
There are at least 5 different ways a garbage collector is called in android one of the common and I know you always see this when you look at the logcat
is 在Android中,至少有5种不同的方式来调用垃圾收集器,这是常见的一种,我知道当您查看
logcat
时总是会看到这种情况。
GC_CUNCURRENT
it is a concurrent collection
that is triggered when the heap start to fill up. 它是在堆开始填满时触发的
concurrent collection
。
GC_FOR_MALLOC
it is called when GC_CUNCURRENT
was not able to completed in time and that the heap is full and also device need to allocate more memory then this is triggered, the garbage collection directly executed. 当
GC_CUNCURRENT
无法及时完成并且堆已满,并且设备需要分配更多的内存时GC_CUNCURRENT
调用该函数,然后触发此操作,直接执行垃圾回收。
GC_EXTERNAL_ALLOC
this is only called in API below HONEYCOMB
where it is triggered when you release memory to the Bitmap pixel data by calling recycle()
method of it. 仅在
API below HONEYCOMB
调用此API below HONEYCOMB
,当您通过调用其recycle()
方法将其释放给位图像素数据时触发该API below HONEYCOMB
。
GC_HPROF_DUMP_HEAP
this is called when you create an hprof file from the DDMS
for memory analyzation
or locating the memory leak
. 从
DDMS
创建hprof文件进行memory analyzation
或查找memory leak
时,将调用此方法。
GC_IMPLICIT
now this is called when you are calling the garbage collector itself through System.gc()
, Beware: avoid calling this and that you should trust the garbage collector
. 现在,当您通过
System.gc()
调用垃圾收集器本身时会调用此方法, 请注意:避免调用此方法,并且应该信任garbage collector
。
Why GC skips bitmaps? 为什么GC会跳过位图?
That is because you need to implicitly call the recycle method of the Bitmap to call the garbage collector to recycle the bitmap pixel data of it. 那是因为您需要隐式调用Bitmap的recycle方法来调用垃圾回收器,以回收其位图像素数据。 Every bitmap from
HONEY and above
are store in the dalvik heap
. HONEY and above
中的每个位图都存储在dalvik heap
。
What does GC do with not needed object? GC对不需要的对象有什么作用?
As long as the object have reference
somewhere it wont be garbage collected and will result to memory leak, you can use DDMS to check the memory leak of your application. 只要对象在某处具有
reference
,就不会对其进行垃圾回收,并且会导致内存泄漏,您可以使用DDMS检查应用程序的内存泄漏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.