Reputation: 1056
I have an app where i use ViewPager and set in every page"Fragment" an image.
when i scroll the view pager after image 25 it is giving me out of memory exception but i delete the image every time go to next page.
check code below:
public void destroyItem(View collection, int position, Object view) {
Log.d("**", "remove image");
((ViewPager) collection).removeView((ImageView) view);
} //method: remove item from pager adapter
i tried code from here to delete ImageView but it did not solved the problem:
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
edit:
below code will solve the problem, but i want to use the full image size and why it is not delete the image?
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2; //reduce image size
Upvotes: 0
Views: 1094
Reputation: 30168
There are two possible issues:
recycle()
after your remove them from the views. This makes sure the GC can reclaim the memory. Be careful if these Bitmaps are reused in any of the other views though.Upvotes: 1