简体   繁体   中英

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.

When system calls GC ?

What GC in android counts as not needed?

Why GC skips bitmaps?

Sample of code that shows how we can bypass GC ? (Object = null ?)

What does GC do with not needed object?

Other important facts...

** When system calls GC? What GC in android counts as not needed? **

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

GC_CUNCURRENT

it is a concurrent collection that is triggered when the heap start to fill up.

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_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.

GC_HPROF_DUMP_HEAP

this is called when you create an hprof file from the DDMS for memory analyzation or locating the 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 .

Why GC skips bitmaps?

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. Every bitmap from HONEY and above are store in the dalvik heap .

What does GC do with not needed object?

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.

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