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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:25:39+00:00 2026-05-28T20:25:39+00:00

i have to display 20 same balls jump at the same style at different

  • 0

i have to display 20 same balls jump at the same style at different positions. but i keep getting the error: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
.

at first i tried with xml files in anim folder. but i can’t release any resource declared in xml. so i changed to create Bitmap with BitmapFactory, and call recycle function. but i can’t get over either.

the code flow is something like this:

Bitmap[] ballBitmap;
int[] playOrder = new int[2];   //the balls will play in order of the definiens in playOrder
ImageView[] balls = new ImageView[20];  //it contains 20 balls

private void iniNewQuestion() {
passNum++;
if(passNum > 1) clearPic();
if(passNum < 20) playBall();
}


private void playBall() {
int ballIndex = playOrder[passNum - 1] - 1;
ballBitmap = new Bitmap[9];
ballBitmap[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_up_01);
ballBitmap[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_up_02);
ballBitmap[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_up_03);
ballBitmap[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_up_04);
ballBitmap[4] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_up_05);
ballBitmap[5] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_flat_06);
ballBitmap[6] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_flat_07);
ballBitmap[7] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_flat_08);
ballBitmap[8] = BitmapFactory.decodeResource(context.getResources(), R.drawable.game_ball_flat_09);

AnimationDrawable ballAnimation = new AnimationDrawable();
for (int picIndex = 0; picIndex < 9; picIndex++) 
{
    ballAnimation.addFrame(new BitmapDrawable(ballBitmap[picIndex] ), breakTime[picIndex]);
    //if(picIndex > 0) ballBitmap[picIndex].recycle();
}

ballAnimation.setOneShot(true);
balls[ballIndex].setBackgroundDrawable(ballAnimation); 
ballAnimation.start();

Handler toNextQuestionHandler = new Handler();
toNextQuestionHandler.postDelayed(runIniNewQuestion, 3000);
}

private Runnable runIniNewQuestion = new Runnable() { public void run() { iniNewQuestion(); } };

private void clearPic() {
    int picIndex = 0; 
    for (picIndex = 0; picIndex < 9; picIndex++) 
    {
            if(ballBitmap[picIndex] != null ) 
            {
                    if(!ballBitmap[picIndex].isRecycled()) ballBitmap[picIndex].recycle();
            }
    }
}

it always happens when I play the 6th ball. the error log is:

01-28 05:29:31.927: E/AndroidRuntime(1090): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.Bitmap.nativeCreate(Native Method)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
01-28 05:29:31.927: E/AndroidRuntime(1090): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
01-28 05:29:31.927: E/AndroidRuntime(1090): at com.gzconcern.animalaba.AbaGame.playBall(AbaGame.java:533)

I thought when I add a frame to ballAnimation, i have new a Bitmap from the picture, so I should release the picture right away. but when I do call recycle, it turns out this:

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@44e85c60

  • 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-28T20:25:40+00:00Added an answer on May 28, 2026 at 8:25 pm

    It’s a common issue when using heavy bitmaps at runtime. Hopefully some of the solutions given here will work for you http://code.google.com/p/android/issues/detail?id=8488
    Another thing which you should do is monitor the runtime memory of your application in DDMS.
    To monitor it, select the device, then your application. Then select the green icon at the top which says ‘Update Heap’. Then open the window for ‘Heap’ and select ‘Cause GC’.
    There you will see the memory available for you application and the actual memory consumed by your app.

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

Sidebar

Related Questions

Java can display png, jpg a some other picture formats, but i have to
I have two pages that should display the same, but on the second one
Is it possible to have multiple view of the same display object? (e.g. same-computer
is it not possible to have both CLICK and DOUBLE_CLICK on the same display
I have an asp.net mvc 2 app. I need to display the same page
I have a pair of views in my application that both display the same
i have to parse a RSS feed and display the same in android. i
I have to display different feeds in different section in a single page, for
i am running into the same problem again, i have some display:none elements on
I have a page that renders two panels that display the same data differently

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.