java - OutOfMemoryException thrown due to ImageCache Memory Leak on Android -
so think i've found source of memory leak. based on article: http://android-developers.blogspot.ca/2009/01/avoiding-memory-leaks.html it's bad have static bitmap drawable , set on imageview. because, once set (imageview.setimagebitmap(bitmap)) imageview set callback on bitmap. hence, on rotate, bitmap, since it's static, remains , still contains callback previous imageview, has reference previous activity. hence previous activity not destroyed!
i believe have similar issue, it's not due static variable, singleton imagecache class. imagecache alive while app running , called using getinstance(context context). each bitmap stored in gets set on imageview @ point.
the memory leak: when screen rotated, bitmap, still in memory, has callback previous image view. hence, previous activity not destroyed. don't, however, want recycle , destroy bitmap it's used elsewhere in app. think need remove specific imageview being destroyed bitmaps callback set. how do this? or analysis wrong? appreciate help!
update:
so looks source of problem viewpager in activity. basically, have fragment viewpager i've added header of listview. is, call mlistview.addheaderview(mviewpager);
works fine, until rotate screen. once rotate screen notice fragments being leaked. example, start app 3 fragments in viewpager. when rotate, notice original 3 re-created , additional 3 created. not visible user though! previous 3 being held onto in background reason. i'm able see tracking onpause()
, oncreate()
calls fragment. idea why happening?
here's sample code:
mstatusview = inflater.inflate( r.layout.header, (viewgroup) getactivity().findviewbyid( r.id.list_header)); mlistview.addheaderview(mstatusview, null /*data*/, false /*isselectable*/); mlistview.setselectionafterheaderview(); .... mheaderpager = (scrollableviewpager) mstatusview.findviewbyid(r.id.header_pager);
in above code, mstatusview entire view, other elements. mheaderpager viewpager within mstatusview.
Comments
Post a Comment