1

I have a ViewPageron my Kindle Fire app that adds roughly 30 views per Page Activity. There are no references to the bitmaps once they are added (the vars are lost after the local statement block closes).

What's the easiest way to recycle all of my bitmaps when their parent view is removed? I need to do this because after swiping a few pages, my app closes because there's no more memory to allocated from because apparently non-recycled bitmaps will not release their memory.

Thoughts?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • use 'destroyItem' to remove item from your `ViewPager`. – Herry May 04 '12 at 05:32
  • @Herry I'm already doing that, but watching the allocations it seams like the bitmap data never gets released. I'm finding out that the data will not get released unless you call a recycle on your images. Does that sound accurate? – Jacksonkr May 04 '12 at 13:19
  • have use Some List view hold images object like `Bitmap` or `Drawable`.if image are big then you need to use recycle . – Herry May 04 '12 at 13:32
  • follow to load image in `ViewPager` from this http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966 – Herry May 04 '12 at 13:33
  • The bitmaps are roughly 10.5k a piece and there are 25-30 on each "page". After 8 pages there is somewhere around 2.1-2.5 mb soaked up. My app only crashes when I've swiped around a number of times. Is there a way to run a recycle on images that are being removed from the screen? – Jacksonkr May 04 '12 at 13:36

1 Answers1

5

you said that you have use Viewpager in application then make sure in it's PagerAdapter adapter you have use below method.

@Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            // TODO Auto-generated method stub
            ((ViewPager)container).removeView((View)object);
        }

this method remove page which is not display at current screen and in this method

@Override
        public Object instantiateItem(ViewGroup container, int position) {
}

in this method load Image Efficiently , for that you can refer android developer site .displaying bitmaps

Herry
  • 7,037
  • 7
  • 50
  • 80
  • This isn't exactly what I was looking for, but there must be something about removing the views that causes the bitmaps to recycle automatically. Maybe because I have `inPurgeable = 2` ? – Jacksonkr May 09 '12 at 00:46
  • Had the same problem. Turns out I didn't remove the View from the ViewGroup but did recycle the bitmaps. – Eugen Timm Aug 21 '14 at 11:46