Jacksonkr
Jacksonkr

Reputation: 32227

android recycle all bitmaps in view on view removal

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?

Upvotes: 1

Views: 3395

Answers (1)

Herry
Herry

Reputation: 7087

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

Upvotes: 5

Related Questions