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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:08:21+00:00 2026-06-11T04:08:21+00:00

I am pretty new to Android and have been developing a game. Every now

  • 0

I am pretty new to Android and have been developing a game. Every now and again I have users reporting out of memory exceptions, which I find surprising since the bitmaps that I create are at most 200 kb in size. I call BitmapFactory.decodeResource() whenever I create a new sprite. Since my application is a zombie defense game, you could expect that I create sprites quite often.

Every time I create a sprite, I call decode resource to generate a bitmap. My question is if I was to only call decode resource at the start of each activitiy, and refer to the bitmap at package level, would this lessen the amount of memory placed on the VM Budget?

  • 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-11T04:08:23+00:00Added an answer on June 11, 2026 at 4:08 am
    • When you decode the Bitmap from an image resource like png, it
      depends more on the dimensions of image rather then the size in KBs.
    • Try if you can reduce the dimensions of original image without really impacting your output.
    • Try reusing the bitmaps rather then keep decoding them.
    • Explore more options with BitmapFactory.Options() object, for example increasing inSampleSize can reduce the amount of memory required by the image.
      e.g

      BitmapFactory.Options o=new BitmapFactory.Options();
      o.inSampleSize = 4;
      o.inDither=false;                     //Disable Dithering mode
      o.inPurgeable=true;                   //Tell to gc that whether it needs free memory, the Bitmap can be cleared
      myBitMap=BitmapFactory.decodeResource(getResources(),ID, o);
      

    • One useful tricky solution if no other optimizations are really working out for you is that, you can catch the OutOfMemoryException and then can reduce the quality to max.. i.e. setting the inSampleSize to 16. It will reduce the quality of your images but at least will save your application from crashing, i did this in one of my app where I needed to load huge MP image in a bitmap.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm pretty new to android development and have been trying to piece together
I am still pretty new to Android development, and I have not been able
I'm new to both android and game development and have been trying to create
I have been developing android applications for about 1 month now I am getting
I am completely new to android, and pretty much a Java newb. I have
I'm pretty new to Android dev and still working out a lot of things.
I am pretty new to android. I have a use case where I need
I'm pretty new to android development, and I've been having some problems getting my
still pretty new to android I have to clone an iphone application. Im having
I'm pretty new to Android but I have some experience (and a bit rusty

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.