0

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 ?

Regards,

Olivier

Olivier
  • 1
  • 2

2 Answers2

0

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.

Haphazard
  • 10,900
  • 6
  • 43
  • 55
0
  1. 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

  2. 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

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks for you answer, I am caching drawable but I clear the callback reference when I destroy my Activity. I think it's better to cache drawable, because otherwise each time you set a bitmap to an imageView you create indirectly an new drawable. My problem is more, I have got a leak on bitmaps, but I don't retain any activity in memory, but How can I find this leak ? – Olivier May 16 '11 at 09:55