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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:27:13+00:00 2026-06-13T12:27:13+00:00

I’m working on a android game. Problem starts when I try to use 3

  • 0

I’m working on a android game. Problem starts when I try to use 3 images for background. Images are 1280x720px and 100kb large.
The images are really not that big, so I’m bit confused why they should cause memory problem.

Note: Screen resolution is 800×400 so I cant really resize image by factor 2 as it is suggested on android developer
Note: I’m using HTC desire phone (here crash comes), I’ve also tried it on Samsung Galaxy S1 and on Samsung it works OK.

I’ve analysed memory in DDMS and what is strange is I found that Heap is only 3.5mb large. If I check rt.MaxMemory() it says I have around 25mb of space per app.

What comes to my mind is that heap isn’t “updating” fast enough to accommodate for larger photos/apps, so it crashes before it can load images despite being so small. Is there any way to manualy set heap size, or at least tell it to enlarge?

Here is code where I load images:

        Bitmap floorFront = BitmapFactory.decodeResource(host.getResources(), R.drawable.floor1);
        floorFront = Bitmap.createScaledBitmap(floorFront,host.realWidth,host.realHeight, true);
        floorFront = Bitmap.createBitmap(floorFront, 0, host.realHeight/2, host.realWidth, host.realHeight/2);
        host.addInstance(new Background(0,host.realHeight/2,host,floorFront,1));

        Bitmap floorBack = BitmapFactory.decodeResource(host.getResources(), R.drawable.sand);
        floorBack = Bitmap.createScaledBitmap(floorBack,host.realWidth,host.realHeight, true);
        floorBack = Bitmap.createBitmap(floorBack, 0, host.realHeight/2, host.realWidth, host.realHeight/2);
        host.addInstance(new Background(0,host.realHeight/2,host,floorBack,4));

        Bitmap floorRock = BitmapFactory.decodeResource(host.getResources(), R.drawable.foreground);
        floorRock = Bitmap.createScaledBitmap(floorRock,host.realWidth,host.realHeight, true);
        floorRock = Bitmap.createBitmap(floorRock, 0, host.realHeight/2, host.realWidth, host.realHeight/2);
        host.addInstance(new Background(0,host.realHeight/2,host,floorRock,0));

Here is exact error from LogCat:

 maxMemory:25165824
 memoryClass:24
 6144000-byte external allocation too large for tgis process.
 Out of memory: Heap Size=4739KB, Allocated=2399KB, Bitmap Size=18668KB
 VM won't let use allocate 6144000bytes

EDIT:
Now that you said it makes sense that bitmaps use “raw” size of image and not compressed. And after some research it seems that on android 2.2 and 2.3 bitmaps are not stored in heap therefore heap doesn’t increase after image is loaded.

I have one more question. We use those 3 images for background. We will now resize them a bit in vertical direction, but in horizontal we still kind of need them as they are. So the image will still be around 100x720px. The problem why we need 3 images is, so we can draw them separately and get layers effect (we can draw something between 2 images). What would be the best way to implement this to get desirable effect with as little of memory to use as possible?

Background:
background
Middle:
middle
Foreground
foreground

Note: This are just static backgrounds, animation happens around and between them.

  • 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-06-13T12:27:14+00:00Added an answer on June 13, 2026 at 12:27 pm

    I’m not sure where you get that a 1280 x 720 pixel bitmap is 100KB. It’s really several megabytes. In bytes it is 1280 * 720 * however many bytes per pixel, usually 4 for images with transparency, or 2 for images without. It’s a huge amount of data for a cell phone to load. Maybe you are quoting the size of a compressed image format version such as PNG.

    Some tips to deal with memory usage problems:

    Use Bitmap.Config.RGB_565 input format on your factory if you don’t have any transparency. This saves space versus ARGB_8888.

    Set largeHeap to true on the application element in your AndroidManifest.xml.

    Make sure your bitmaps are not being scaled automatically based on devices density class. Place them in drawable-nodpi, for example, or disable the automatic scaling programatically, or provide a different bitmap for each density class in multiple drawable folders. If your bitmap is only in the drawable folder, it is going to get scaled 2x on XHDPI devices.

    Recycle bitmaps you are not using, e.g.:

    Bitmap floorFront = BitmapFactory.decodeResource(host.getResources(), R.drawable.floor1);
    Bitmap floorFrontScaled = Bitmap.createScaledBitmap(floorFront,host.realWidth,host.realHeight, true);
    floorFront.recycle();
    floorFront = null;
    
    Bitmap floorFrontCropped = Bitmap.createBitmap(floorFrontScaled, 0, host.realHeight/2, host.realWidth, host.realHeight/2);
    host.addInstance(new Background(0,host.realHeight/2,host,floorFrontCropped,1));
    

    You can also manually run System.gc() at times. The system is supposed to do that for you before returning an OutOfMemoryError, but it doesn’t with bitmaps in Android because they have memory allocated outside Java.

    Note that when you read in a Bitmap, you can actually check if the size you need it at is a whole number divisor less than its size, then specify the factory should skip over pixels when loading. This can help on smaller resolution devices, which have correspondingly smaller memory limits.

    If you are not moving these background images separately, then draw them all to a single bitmap and use that instead of three at once.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.