android - java.lang.outofmemoryerror bitmap on a fragment pager -


i have memory leak problem can't find way solve. there many questions in stackoverflow no 1 of them useful me.

i have activitiy view pager , action bar tabs navigation. in every fragment load 1 image sort of gallery in end. works nice.

after fragment changes, got error:

e/androidruntime(19271): java.lang.outofmemoryerror e/androidruntime(19271): @ android.graphics.bitmap.nativecreate(native method)

all i've read need of deallocating images, thought about:

  1. event @ "fragment lost focus"
  2. delete views inside fragment focus has lost

but can't find solution that. correct way? if so, can give example? or i'm wrong , solution way?

this how add images fragment:

             imageview img = new imageview(rootview.getcontext());              img.setvisibility(1);              img.setimageresource(r.drawable.gallery_image_1);              img.setadjustviewbounds(true);              img.settag( "gallery_image_1" );              gallery.addview(img); 

thanks in advance!

diego

first of all, make sure you're using fragmentstatepageradapter, it's more memory-friendly fragmentpageradapter.

second, analyze application mat find causes memory leaks. here's excellent post describing how tool can used in context of android.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -