2

Situation:

I'm developing an app, which is some sort of photo frame app (there's 16 frames user can choose from), which consists of:

  • ViewPager with maximum 5 ListView. (Off screen limit is set to 1, so we can assume only 3 ListViews will be in memory)
  • Each ListView has 17 view types (16 frames + Loading view)

We all know Android saves our off-screen rows as convertView in memory. So, in my situation, worst case, I might end up with 17 convertViews * 3 ListView = 51 views in my memory (maybe less, maybe more, not important).

While simple 51 Views wouldn't consume a lot of memory (I assume). My views are all filled up with decent bitmap, which is fairly big memory consumption.

Question:

Is there anyway I can detect a view becoming off-screen (or becoming convertView) so that I can instantly release the reference to its drawable?

My Progress:

I've been looking at adt bundle's source code (Api 16) for AbsListView on putting a scrapView into RecycleBin, I believe the detection can be done there but that would require me to customize the whole class. My worry is older Api can't support what within Api 16, so I'm asking here to see if there is any other better options.

Thank you for your time.

Chor Wai Chun
  • 3,226
  • 25
  • 41
  • 4
    Sounds like you may be looking for [`RecyclerListener`](http://developer.android.com/reference/android/widget/AbsListView.RecyclerListener.html), which you can set on any (extension of) `AbsListView`. In the callback you get access to the view that was just placed on the scrap heap. The documentation explicitly states that is the right place to free up any resources associated with the view. – MH. Oct 05 '13 at 23:22
  • @MH. Awesome! I almost gave up as my progress requires me to copy a lot of dependencies from Android sources. I'll have a look into that, thanks! – Chor Wai Chun Oct 06 '13 at 02:45

0 Answers0