1

I have developed a custom list adapter where i have attach views using holder. also i have checked if the views are already crated and reusing them again and again. The listview is inside the fragment and when I am navigating to another fragment I am using fragmenttransaction.replace . But issue is that when i monitor the dump file using MAT I found the imageview that were present inside adapter still hold the reference to bitmaps. Even different others views had the reference.

I want to know how to remove reference to that views?

Suraj Pohwani
  • 138
  • 1
  • 9
  • You can clean the imageview by giving a null object. However, until garbage collection was not started it's absolutily ok still having those objects in memory. – brummfondel Jul 08 '14 at 13:13
  • `if (mBitmap != null) { mBitmap.recycle(); mBitmap = null; }` – makata Jul 08 '14 at 13:33
  • 1
    See [this SO question](http://stackoverflow.com/questions/4959485/bitmap-bitmap-recycle-weakreferences-and-garbage-collection) for more on memory mgt. – makata Jul 08 '14 at 13:34
  • @mek the post you referred i have done that way, but issue is that the hard reference is still prevailing to the ImageView inside the adapter. And that resist the GC to recycle bitmaps. So I need way to remove reference to views inside the adapter. – Suraj Pohwani Jul 09 '14 at 06:20

1 Answers1

0

try to setAdapter(null); and you can try to use WeakReference

Mike
  • 2,547
  • 3
  • 16
  • 30
  • Actually i did that where i used my adapter. But makes only adapter null not its views inside it, so the views that are inside adapter have reference. – Suraj Pohwani Jul 09 '14 at 06:15