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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:22:46+00:00 2026-05-15T17:22:46+00:00

I am having an OutOfMemory exception with a gallery over 600×800 pixels JPEG’s. The

  • 0

I am having an OutOfMemory exception with a gallery over 600×800 pixels JPEG’s.


The environment

I’ve been using Gallery with JPG images around 600×800 pixels.

Since my content may be a bit more complex than just images, I have set each view to be a RelativeLayout that wraps ImageView with the JPG.

In order to “speed up” the user experience I have a simple cache of 4 slots that prefetches (in a looper) about 1 image left and 1 image right to the displayed image and keeps them in a 4 slot HashMap.

The platform

I am using AVD of 256 RAM and 128 Heap Size, with a 600×800 screen.
It also happens on an Entourage Edge target, except that with the device it’s harder to debug.


The problem

I have been getting an exception:

OutofMemoryError: bitmap size exceeds VM budget

And it happens when fetching the fifth image. I have tried to change the size of my image cache, and it is still the same.


The strange thing: There should not be a memory problem

In order to make sure the heap limit is very far away from what I need, I have defined a dummy 8MB array in the beginning, and left it unreferenced so it’s immediately dispatched. It is a member of the activity thread and is defined as following

static { @SuppressWarnings("unused")
byte dummy[] = new byte[ 8*1024*1024 ]; }    

The result is that the heap size is nearly 11MB and it’s all free.
Note I have added that trick after it began to crash. It makes OutOfMemory less frequent.

Now, I am using DDMS. Just before the crash (does not change much after the crash), DDMS shows:

ID  Heap Size   Allocated   Free       %Used    #Objects
1   11.195 MB   2.428 MB    8.767 MB   21.69%   47,156  

And in the detail table it shows:

Type  Count  Total Size   Smallest   Largest   Median    Average
free  1,536  8.739MB      16B        7.750MB   24B       5.825KB

The largest block is 7.7MB. And yet the LogCat says:

ERROR/dalvikvm-heap(1923): 925200-byte external allocation too large for this process.

If you mind the relation of the median and the average, it is plausible to assume that most of the available blocks are very small. However, there is a block large enough for the bitmap, it’s 7.7M. How come it is still not enough?

Note: I recorded a heap trace. When looking at the amount of data allocated, it does not feel like more than 2M is allocated. It does match the free memory report by DDMS.


  • Could it be that I experience some problem like heap-fragmentation?
  • How do I solve/workaround the problem?
  • Is the heap shared to all threads?
  • Could it be that I interpret the DDMS readout in a wrong way, and there is really no 900K block to allocate? If so, can anybody please tell me where I can see that?

Thanks a lot

Meymann

  • 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-15T17:22:47+00:00Added an answer on May 15, 2026 at 5:22 pm

    I think there’s nothing special in your case. There’s just not enough memory. You can’t have several 600×800 bitmaps in memory, they consume too much memory. You should save them to SD and load to memory on demand. I think that’s exactly what you do.

    One thing you should be aware of: DDMS displays java heap memory consumption. But there’s also native memory that is not displayed in DDMS. And bitmaps as far as I understand are created in native memory. So DDMS is just a bad tool to track these memory issues. You just need to be sure that you free your memory, that images are collected by Garbage Collector after you don’t need them any more.

    Garbage Collector works on it’s own schedule. That’s why you should call Bitmap.recycle() method on bitmaps that you don’t need any more. This method frees exactly the native memory that you run out of. This way you don’t depend on GC and you can free largest piece of memory as soon as possible.

    First of all you should ensure that you don’t leak bitmaps.

    Here’s a nice post on memory allocations, it can help you to dig deeper

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

Sidebar

Related Questions

Having been a PHP developer on LAMP servers for quite a while, is there
I am having difficulty using the Java JAI (Java Advance Imaging) API to change
I am working on an app having a lot of image and using a
Having successfully got a WCF service and client to talk to one another using
I've thrown myself headfirst into C# and .Net 2.0 using Linq, and I'm having
Having trouble with Delphi XE2 (update2) using MS SQL 2008 R2 (sp 2) or
Having trouble using libstatgrab -- I receive the following error at compile time: libstatgrabTest.cpp:16:
Having a issue where all mobile devices is zoomed 50% in at start. That
Having got a chunk of my application working with Entity Framework 4.1, I needed
Having the function name 'foo' and its argument 'arg' in strings, is there 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.