Android, I see the heap is growing, but I want it to stop

I see that my pile is growing, and I know that it will eventually crash on any device, as it just keeps growing.

Grow heap (frag case)

observed in all magazines

on my phone, this will cause the 32 MB application to crash. Other phones, of course, will be 16 MB, if there are any resources with a small amount of resources that run Android 2.2

Now I use recycle() in my bitmaps, setting things to zero, popping up elements from complex data structures, and using System.gc() to invoke garbage collection throughout the application

but the heap is still growing and its problem ... in the end

How to just make the application dump resources so that it can continue to work.

usually always "budget vm bitmap" exceeds, but I feel more and more that I simply do not have access to the "clear bitmap vm" command

+3
source share
1 answer

I also struggled a lot with this problem. There are many things you can do.

  • You can call processing on each bitmap and set them to null. ( bitmap.recycle() with relaese all the memory used by this bitmap, but does not invalidate the bitmap object).

  • you can also untie the drawables associated with the layouts as indicated in this link .

  • You can convert hashmaps to WeakHashmaps . so that his memory will be restored when the system runs with low memory.

  • You can resize all your bitmaps. look at this ink <.

  • you can override the onLowMemory() method in an activity that gets called when the whole system is running low on memory. you can free several resources there.

  • you can create your SoftReference or Weakreference objects so that they are freed in low memory conditions.

But the real fact is that all this can DELAY your memory shortage problem / crash, but it cannot fix it, because the point is that somewhere you should leak your activity or memory context somewhere.

+16
source

Source: https://habr.com/ru/post/1387154/


All Articles