09-28 17:16:37. 543: Debug/dalvikvm (21466): gc_external_alloc freed 390 objects/45656 bytes in 50 ms
09-28 17:16:40. 513: Debug/dalvikvm (3267): gc_explicit freed 4501 objects/251624 bytes in 67 Ms
Many developers do not understand what the above sentence means. I 'd like to explain it to you!
The preceding free memory is the memory used by Java in the VM. External refers to the memory allocated by malloc in the native class in JNI, such as bitmap and some cursor.
In davilk, the memory allocated to a program varies with the model vendor. Most of the current memory is 32 MB, in the VM, the memory is divided into memory used by Java and memory used by native, which cannot be shared. That is to say, when your native memory is used up, now Java has idle memory, and Native will apply again like VM instead of using Java directly.
Example:
Free 3411 K/6663k and external 24870 K/26260 K
If you need to create a 2 m
Bitmap
Native's existing memory is 26260-24870 = 1390 k <2048 K, so he will apply for memory from the VM, although the Java idle memory is
6663-3411 = 3252> 2048, but this part of memory native is not available.
However, if you apply for 2 MB native memory, the VM will tell you that it cannot be allocated because the used memory is close to the peak of 32 MB (26260 + 6663 = 32923 ), therefore, force close reports oom.
So now we need to check the usage of our native memory to avoid oom.