Android, An impossible Memory Leak, How to find it with eclipse?
I am metting an OutOfMemory exception after a while, while inflating an XML View with a bitmap.
The problem occurs after opening many times activities that are using many bitmap but always inflated from the XML.
I check with MAT the Memory. First question : I don't retain any of my Activity in memory - If I filter on the name of my Activity, i get Objects = 0, but on some activities I could see RetainedHeap >= 302. Does this indicate a leak ?
After that, I try to compare my memory in different point of time, to see the objects that have been created. But I can't find any thing significant.
My Question is : If I don't retain activities in memory what could be the leak reason ? What tools/Method to use to find it ?
Reg开发者_StackOverflow中文版ards,
Olivier
Try setting all references to the bitmaps to null
when the Activity is destroyed. This may not answer your questions but it should solve your problem.
If you have big source images then scale them to target size: Strange out of memory issue while loading an image to a Bitmap object
Cache Bitmaps (but not Drawables!!) in a List (or Map) and save them in
onRetainNonConfigurationInstance()
: http://developer.android.com/resources/articles/faster-screen-orientation-change.html
精彩评论