Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:02:40+00:00 2026-05-22T02:02:40+00:00

I am building a book viewer for Android 3.0 Honeycomb. It has been working

  • 0

I am building a book viewer for Android 3.0 Honeycomb. It has been working fine on the Samsung Galaxy Tab but gets a lot of OutOfMemoryErrors on the Motorola Xoom on 3.0.1. Both devices have 48MB VM heap space.

I have 2 activities:

BookActivity – has a SlowGallery which loads 1280×640 images and a small Gallery which loads 160×80 images.

The SlowGallery is a minor override to make it fling one gallery item at a time instead of scrolling quickly.

BitmapActivity – has a single ImageView which loads an 4488×2244 image and a small Gallery which loads 160×80 images. Reducing the size of the image is not an option because the user is intended to enlarge the image to 100%.

I put this in the Bitmap-loading method to reduce the bitmap to 16-bit:

BitmapFactory.Options o2 = new BitmapFactory.Options();
if (compressColor) o2.inPreferredConfig = Bitmap.Config.RGB_565;
o2.inPurgeable = true;
o2.inInputShareable = true;
o2.inSampleSize = (int) scale;
b = BitmapFactory.decodeStream(fis, null, o2);

When I double-tap the BookActivity’s Gallery, it calls BitmapActivity, passing the respective image number to be opened. I can do this 1-3 times, entering the BitmapActivity, then clicking Back, before it hits an OutOfMemoryError.

On double-tapping the Gallery it calls PageAdapter.purge(), which appears to visually unload the gallery’s images.

This is BookActivity.PageAdapter, which is the adapter for the SlowGallery:

private class PageAdapter extends BaseAdapter {
private final LayoutInflater mInflater;
private Page currentPage;
private boolean purge = false;
private WeakReference<Bitmap> weakReferenceBitmap;
public PageAdapter(Context context) {
    mInflater = LayoutInflater.from(context);
}
public void unpurge() {
    purge = false;
    notifyDataSetChanged();
}   
public void purge() {
    purge = true;
    holder = null;
    notifyDataSetChanged();
}       
@Override
public int getCount() {
    if (listPages==null || purge) return 0;
    return listPages.size();
}
@Override
public Object getItem(int position) {
    return null;
}
@Override
public long getItemId(int position) {
    return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.gallery_pages, null);
        holder = new ViewHolderIssues();
        holder.image = (ImageView) convertView.findViewById(R.id.ImageViewPage);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolderIssues) convertView.getTag();
    }
    if (position < listPages.size()) {
        currentPage = listPages.get(position);
        File f = new File(Engine.PATH + currentPage.getImageMedium());
        if (!purge) {
            if (!f.exists()) {
                holder.image.setImageResource(R.drawable.loading);
                Engine.triggerTrickle(currentPage.getImageMedium(), WeightedAsset.IMAGE_MEDIUM, getApplicationContext());                   
            } else {
                weakReferenceBitmap = new WeakReference<Bitmap>(Engine.loadImageFromBitmap(currentPage.getImageMedium(), screenWidth, 1, true));
                if (weakReferenceBitmap.get()!=null) {
                    holder.image.setImageBitmap(weakReferenceBitmap.get());
                } else {
                    holder.image.setImageDrawable(null);
                }
            }
        } else {
            weakReferenceBitmap.clear();
            holder.image.setImageDrawable(null);
            holder = null;
            System.gc();
        }
        f = null;
    }
    return convertView;
}
}

Looking at the HPROF file, under the Dominator Tree, it appears that the BookActivity.SlowGallery still exists even when I am in BitmapActivity. When in BookActivity, SlowGallery takes up 3.2-6.5MB (1.6MB per image) but in BitmapActivity it takes up 1.6MB (SlowGallery.LinearLayout.ImageView.BitmapDrawable = 1.6MB). How do I get rid of SlowGallery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:02:41+00:00Added an answer on May 22, 2026 at 2:02 am

    Ah, kinda complex chunk of code there. The weak references may help, but in general, if using an ImageView in an adapter, before you set the new bitmap you should fetch the old Bitmap and then call Bitmap.recycle(). You should also do that your BitmapActivity when it is destroyed. That should do most of what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building on what has been written in SO question Best Singleton Implementation In Java
screenshot I'm following a tutorial (book) about building rails apps but i ran into
I'm building my first Android program from a book. It kept crashing on an
I asked this question on programmers , but it has been crickets for a
Am building a Book search API using Lucene. I need to index Book Name,Author,
When building some of my PHP apps, a lot of the functionality could be
I am building a book where I will use the page curl animation to
I am reading The thread building block book. I do not understand this piece
I am building a simple book check out application. One of the things that
I am reading the book: Intel Threading Building Blocks. I often have difficulties understanding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.