Digging further on my problem, I do realize that what I was doing was STUPID.
On the screen rotation, my Fragment will be paused/stoped and then its View will be destroyed (onPause/Stop and onDestroyView), my activity will be destroyed and then recreated. The framework would take care of reattaching my Fragment to the new Activity, and from the Lifecyle of Fragments it will call onCreateView, which will return a new View hierarchy, and here lies the problem, because on my adapter (wich is retained with the fragment) I was using a setTag to save the viewholder, but this view is no longer available (onDestroyView) but it still has a reference to it, by my Adapter which still has a reference to my activity, leaking the context. So, here is my question again, there is some way to use the ViewHolder pattern on this case? Or should not care about it? LĂșcio Maciel [email protected] On Mon, Oct 3, 2011 at 23:27, luciofm <[email protected]> wrote: > 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 > [email protected] > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

