Android, I see the heap grow, but I want it to stop

I see more and more of my heap, and I know it will eventually crash on any device because it will keep growing

Frag case

You can see it in the whole log

On my phone, it will crash with 32MB applications. Other phones are of course 16MB. If there are a few resources to run Android 2.2

Now, I use recycle () on my bitmap, set things up to null, pop-up items from complex data structures, and use System.gc () to call garbage collection in the entire application.

However, the heap is still growing and eventually problems will occur

How do I force an application to dump resources so that it can continue running

It usually exceeds the "bitmap VM budget", but I feel more and more. I just can't access the "clear bitmap VM" command

resolvent:

I also encountered many difficulties on this issue. You can do a lot of things

>You can call recycle on each bitmap and set them to null. (bitmap. Recycle () with relax all the memory used by this bitmap, but will not invalidate the bitmap object). > you can also unbind the drawable associated with the layout specified in this link. > you can convert hash maps to weakhashmaps. Therefore, when the system memory is low, Its memory will be restarted. > you can adjust the size of all bitmaps. Look at this link.. > you can overwrite the onlowmemory() method in the activity. This method will be called when the whole system is out of memory. You can free some resources there. > you can set objects to softreference or WeakReference so that they can be released under low memory conditions

But the real fact is that all this can delay your memory problem / crash, but it can't eliminate it, because the thing is that you have to leak your active context or memory

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>