Monday, October 3, 2011

[android-developers] ViewHolder Pattern leaking a Context on retained Fragments

Hi,

Recently I've started developing my first fully Honeycomb optimized app.

It uses the setRetainInstance(true) to retain my list fragment on screen rotations.

The odd thing is that I started to observe some very huge leaks on my app, after a few (maybe 6 ou 8) screen rotations my app was getting an OutOfMemoryError. So I go down to investigate it. After using some tips from http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html I've managed to down my leak by half, but it was still a HUGE leak.

So I went further, analyzing the heap dumps on MAT to discover that one cause that I was leaking a Context on every screen rotation was the ViewHolder Pattern.

After removing the ViewHolder pattern from my adapter, doing the findViewById on every getView(), I no longer leak a context and managed to take down my leaks to only 10 or 20k per rotation (which I'm still investigating).

Anyone has gone through the same problem? Is that possible to use the ViewHolder Pattern without leaking the Activity? Or is this Pattern 'deprecated'???

Lúcio Maciel
luciofm@gmail.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate