The difference in the behavior of the garbage collector on the Android device compared to the emulator

I am testing application memory usage on an emulator. And the problem is that on the emulator a bunch of applications only grows and grows, only a few resources are freed. And if collections are not created, this will throw an OutOfMemory exception on higher resolution screens.

I downloaded the Sony SDK, and the Xperia Z has an emulator configuration that has a resolution of 1080x1920, and the default heap is 64 MB. I think this is a small heap size for this resolution because my application uses only 40 MB. However, on my phone it uses 15 MB 64 MB (resolution 540x960). So this rather small heap size (maybe not real?) + GC behavior calls OutOfMemory pretty quickly.

On a real device (I tested only on mine), the GC works very nicely, freeing up resources that are no longer in use, but I really can’t predict whether this will work on other phones.

Should I ignore how the GC works on my emulator, or could it be a problem with my application?

+4
source share
1 answer

A growing heap on the emulator indicates that at some point in your memory leak.

They are very common when you send intentions between different applications (for example, select an image from the gallery). Most devices can handle such leaks without a problem.

Another reason for heap growth: inefficient memory operations. This means that at some point you ask for a lot of memmory (for example, you select a 5M image from the gallery, create an inpuststream for it and save it in memory as a bitmap, so you ask that the 15 + M emulator will only show a heap, but most devices will show an error).

If you see that the heap is growing - analyze the use of your memory and detect leaks. Link
If you don't find anything strange, you can almost safely ignore the heap warning.

Note: the empty space indicated on the heap is not used.

0
source

All Articles