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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:38:12+00:00 2026-05-26T08:38:12+00:00

I am making a game which has to load all bitmaps at start because

  • 0

I am making a game which has to load all bitmaps at start because in the in-built game editor the user can put any of the sprites into the level. Also levels use various sprites without any system which would allow to load groups of sprites dynamically for each level.

After a while the are now already 250+ png images in the game with total size of 3.5MB.

The game loads most sprites (about 200) using BitmapFactory.decodeStream without any options set, and also there are about 50 other which are referenced in xml layouts of activities.

When I test on various devices, the game sometimes runs out of memory, but i can’t find a pattern and even decide by HOW MUCH i have to, e.g. reduce the size of images or their number.

The phone on which i developed, HTC desire with Android 2.2 24MB VM heap size never runs OOM.

Dell Streak with Android 2.2 and 40MB VM heap size never runs OOM, too.

Motorola Milestone with Android 2.1 and 24MB VM heap size successfully loads all sprites but chokes on the few last images used in ImageView’s when starting one of the activities (start menu). If I comment a few of such ImageViews out, it loads ok, but may choke on one of the other activities later. It’s also not stable, probably because fragmentation happens differently in different launches.

HTC hero with 2.2 of my buddy (dunno the heap size, is it 16MB?) crashes as well.

What’s most confusing is that Motorola has 24MB, the same as HTC desire. Is 2.1 implementing memory management less efficiently? (e.g. leads to more fragmentation?) Or is memory management worse by all Motorola phones? Then why does HTC hero with 2.2 crash? What’s bigger in HTC desire than HTC hero?

Looks like OOM happens on older phones, but that’s the only thing I’ve figured out so far.

If OOM only happens on older phones which are, say, 5% of the market, I can just exclude 2.1 or a more specific list from the supported devices by just gathering crash reports and excluding all that crashed from the list of supported. Otherwise I’d now need to scale down all my images by some constant factor (e.g. 1.6), which would mean resizing all the 45 levels which took days and days of designing and testing, repositioning GUI elements etc. Even after that, I’d still not be sure, on which devices the reduction of total size of bitmaps by a factor of e.g. 2 is enough to avoid OOMs.

Any advice on this?
Should I set any specific options for BitmapFactory? btw, most images have transparent bg pixels which, as far as i understand, doesn’t allow getting them in 565 format.

I spent 2 days browsing here and in other places but am still at a loss.

Thank you.

  • 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-26T08:38:13+00:00Added an answer on May 26, 2026 at 8:38 am

    I’ve had to deal with a simpler version of your problem – we had 3 2Mpix layers on top of each other, which, unsurprisingly, sometimes caused OOM.

    In my case, instead of using 3 ImageViews on top of each other, keeping all 6 MPix in memory at all times, I manually blended the layers, thus keeping at most 4 Mpix in memory at any one time (and only 2 MPix at “rest” – the layers changed in our application).

    This is a classic time-space trade-off – sacrifice efficiency (time) to gain memory (space). It was somewhat slow because you had to recycle() each Bitmap after you were done with it to ensure the memory was freed.

    As for the inconsistent OOMs, it probably has to do with garbage collection. You can assume that the garbage collector is non-deterministic and thus any memory pressure becomes non-deterministic as well (depending on when the GC last kicked in).

    The short summary is, you have to be very, very careful with your memory usage and there’s no way around it. *

    * In theory, you could allocate memory outside the Dalvik heap by using the NDK and allocating straight from the OS. It’s a huge hack and the bridge between Dalvik and your allocator will be rather ugly.

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

Sidebar

Related Questions

I'm making a small game, and this has a lot of loops, which all
We are making a game which will add a level editor feature soon. We
I am making a game which has a global (static) class called MedGameController. In
I'm making an iPhone game which has a quite intense use of pixel shaders.
I am making a card game in ruby. I have the Game class, which
I built a slideshow/decision-making game in Flash but would like to try to redo
I'm making a simple 2d game for the android platform, which works perfectly from
I'm making a simple game, and it has a single instance of a class
I'm making a Flash game which will be up on Facebook, I'm using Python/Django
I'm making my first Android game which is going to be a 3D arcade-ish

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.