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

  • Home
  • SEARCH
  • 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 6578633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:47:44+00:00 2026-05-25T15:47:44+00:00

I have an map app. Somewhere in my code I am rendering data from

  • 0

I have an map app. Somewhere in my code I am rendering data from database into canvas.
I ran into “out of memory” exception and I cant figure out how to avoid it.

Here is the relevant method. I get exception when creating bitmap with bitmapfactory.

private static void _renderImage(Canvas g, Point[] points, RImageData imageData, 
                                 RMapView mapView) {

    Bitmap image = (Bitmap)imageData.image;
    Paint paint = new Paint();
    if(image == null) {
        image = BitmapFactory.decodeByteArray(imageData.getImageBytes(), 0,
                                              imageData.getImageBytes().length);
        imageData.image = image;
    }
    g.drawBitmap(image, points[0].x, points[0].y, paint);
}

I have tried recycling the image, but then the canvas coplains it cant work with recycled bitmaps.

Any solution would be much apreciated.

  • 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-25T15:47:45+00:00Added an answer on May 25, 2026 at 3:47 pm

    I would suggest having a bitmap cache. Even recycling images on pre-honeycomb takes time to free memory (Bitmap data is stored in native memory that is not directly managed by dalvik). Here is a sample of a bitmap cache. Please adjust it to your needs.

    /**
     * @author audrius Bitmap cache
     */
    private static class BitmapCache {
        //private static final String TAG = "BitmapCache";
        private final int mCacheSize;
        private final String mBitmapLocation;
        private LinkedHashMap<String, Bitmap> mBitmapCache;
    
        /**
         * Constructor
         * 
         * @param cacheSize
         *            Cache size in element count (e.g. 8 = at most 8 Bitmaps in
         *            cache)
         * @param bitmapLocation
         *            Physical root path to bitmap location
         */
        public BitmapCache(int cacheSize, String bitmapLocation) {
            mCacheSize = cacheSize;
            mBitmapLocation = bitmapLocation;
    
            mBitmapCache = new LinkedHashMap<String, Bitmap>(mCacheSize + 1) {
                private static final long serialVersionUID = -4156123801558395154L;
    
                @Override
                protected boolean removeEldestEntry(
                        java.util.Map.Entry<String, Bitmap> eldest) {
                    return size() > mCacheSize;
                };
    
                @Override
                public Bitmap remove(Object key) {
                    Bitmap bmp = super.get(key);
                    // make sure to release resources as soon as possible
                    bmp.recycle();
                    return super.remove(key);
                }
            };
        }
    
        /**
         * Returns Bitmap (either from cache or physical location)
         * 
         * @param bitmapFilename
         * @return
         */
        public Bitmap getBitmap(String bitmapFilename) {
            Bitmap ret = mBitmapCache.get(bitmapFilename);
            //Log.v(TAG, "getBitmap : " + bitmapFilename);
            if (ret == null) {
                //Log.v(TAG, "Bitmap not cached, reading location : " + mBitmapLocation);
                ret = BitmapFactory.decodeFile(new File(mBitmapLocation, bitmapFilename).getAbsolutePath());
                mBitmapCache.put(bitmapFilename, ret);
            }
    
            return ret;
        }
    
        /**
         * Clears bitmap cache
         */
        public void clear() {
            if (mBitmapCache != null) {
                for (Bitmap bitmap : mBitmapCache.values()) {
                    if (bitmap != null) bitmap.recycle();
                }
    
                mBitmapCache.clear();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an App which launches the google Map App. The code is: UIApplication
I have displayed the map in my app by using the following code. I
I have a route in my code that looks like this: map.app 'applications/:title_header', :controller
I have a scrollable map app which for now has a huge bitmap. It
I have created a simple map app that shows the local garage sales in
I have developed a google map app and the zoom controls will not appear
I hope someone can help with this. I have created a map app that
I have a map in my app, and I want to click a random
I have an application which needs to load data from a remote server (businesses
i have this error in my map app.do you know what is wrong?i have

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.