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 7165463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:15:15+00:00 2026-05-28T14:15:15+00:00

Anyone can help to how to handle bitmap exceeds VM buget error. Actually i

  • 0

Anyone can help to how to handle bitmap exceeds VM buget error. Actually i had displayed more images in a listview. It works fine and throws bitmap error after repeated starting the activity, Any answers are appreciated heartedly.

  • 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-28T14:15:16+00:00Added an answer on May 28, 2026 at 2:15 pm

    public enum BitmapLoading {
    INSTANCE;

    private final Map<String, SoftReference<Bitmap>> cache;
    private final ExecutorService pool;
    private Map<ImageView, String> imageViews = Collections.synchronizedMap(new WeakHashMap<ImageView, String>());
    private Bitmap placeholder;
    
    BitmapLoading() {
        cache = new HashMap<String, SoftReference<Bitmap>>();
        pool = Executors.newFixedThreadPool(5);
    }
    
    public void setPlaceholder(Bitmap bmp) {
        try {
            placeholder = bmp;
        } catch (OutOfMemoryError e) {
            placeholder.recycle();
            bmp.recycle();
            placeholder = null;
            bmp = null;
        }
    }
    
    public Bitmap getBitmapFromCache(String url) {
        if (cache.containsKey(url)) {
            return cache.get(url).get();
        }
        return null;
    }
    
    public void queueJob(final String url, final ImageView imageView,final int width, final int height) {
        /* Create handler in UI thread. */
        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                String tag = imageViews.get(imageView);
                if (tag != null && tag.equals(url)) {
                    if (msg.obj != null) {
                        imageView.setImageBitmap((Bitmap) msg.obj);
                    } else {
                        imageView.setImageBitmap(placeholder);
                        Log.d(null, "fail " + url);
                    }
                }
            }
        };
        pool.submit(new Runnable() {
            @Override
            public void run() {
                Bitmap bmp = null;
                try{
                    bmp = downloadBitmap(url, width, height);
                    Message message = Message.obtain();
                    message.obj = bmp;
                    handler.sendMessage(message);
                }catch (OutOfMemoryError e) {
                    bmp.recycle();
                    bmp = null;
                }
            }
        });
    }
    
    public void loadBitmap(final String url, final ImageView imageView,final int width, final int height) {
        imageViews.put(imageView, url);
        Bitmap bitmap = null ;
        try {
            bitmap = getBitmapFromCache(url);
            if (bitmap != null) {
                imageView.setImageBitmap(bitmap);
            } else {
                imageView.setImageBitmap(placeholder);
                queueJob(url, imageView, width, height);
            }
        } catch (OutOfMemoryError e) {
            bitmap.recycle();
            bitmap = null;
            System.gc();
        }
    }
    
    private Bitmap downloadBitmap(String url, int width, int height) {
        Bitmap bitmap =null;
        try {
            bitmap = BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
            bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
            cache.put(url, new SoftReference<Bitmap>(bitmap));
            return bitmap;
        }catch (OutOfMemoryError e) {
            bitmap.recycle();
            bitmap = null;
            System.gc();
        } 
        catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return null;
    }
    

    }

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

Sidebar

Related Questions

I wonder if anyone can help - I have this error showing recently when
I was wondering if anyone can help me get started with creating a room
Wondering if anyone can help me with this annoying but trivial (in terms of
Wonder if anyone can help me understand how to sum up the column of
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
I wonder if anyone can help me to understand where I could be going
I am new in Symbian UIQ. So anyone can help me out about following
I'm new to querying XML datatype in SQL Server 2005. Anyone can help me
Anyone that can help me out will be very much appreciated. I seem to
To anyone who can help, Thanks Okay, so I have a database holding a

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.