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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:44:13+00:00 2026-05-28T03:44:13+00:00

I am developing an app which instantiates a bunch of bitmap objects (e.g. buttons,

  • 0

I am developing an app which instantiates a bunch of bitmap objects (e.g. buttons, which have cache bitmaps, so they don’t have to get rendered again and again)

Now, I realised that when I run and start the app repeatedly on my huawei mobile device, I get an OutOfMemoryException at a point where the app tries to allocate some memory for the bitmaps.
So I guess it’s the bitmaps which make trouble. I do know that there is a bitmap.recycle() method though.

Now my question: what is best practice to clean up memory?
Why isn’t there some View method like View::onDestroy() which can be implemented for cleanup purpose?

EDIT: example

my “CirclyButton” (extends Button) class always draws a cached bitmap onDraw:

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(this.getDefaultBitmap(), 0, 0, paint);
    }
    private Bitmap getDefaultBitmap(){
        if(mBitmapDefault == null){
            mBitmapDefault = Bitmap.createBitmap(8*radius, 8*radius, Config.ARGB_8888);
            Canvas canvas = new Canvas(mBitmapDefault);
            this.drawDefault(canvas);
            return mBitmapDefault;
        }
        return mBitmapDefault;
    }

So I guess this allocated data should be recycled somewhere…?

  • 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-28T03:44:14+00:00Added an answer on May 28, 2026 at 3:44 am

    Views don’t have an onDestroy method because views usually don’t get destroyed, activities do. A view won’t just be destroyed if nothing happens to its activity (Unless you inflate a different layout… That’s not the case, right?), and if something happens to its activity, you do have a callback getting called.

    If there is a recycle() method, make sure you call it. And remove all reference to memory taking objects in the onDestroy, i.e:

    @Override
    public void onDestroy() {
        object1 = null;
        object2 = null;
        //...
    }
    

    So the GC can do its job. I had the same problem with the AdView of AdMob, although they did have a destroy method it didn’t really help. But deleting my references of the view fixed the problem.

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

Sidebar

Related Questions

I am developing an app in which I have a table. In the table
I have been developing an app in VB.NET which requires a control object (for
I'm considering developing an app for Google App Engine, which should not get too
I am developing a Facebook app. I have a server side OAuth flow which
Hello Everyone, I am developing an app which have to show all the restaurants
I'm developing an app which will have a central database users can add entries
I am developing an app which supposed to work on devices that have OS
I am developing an app which allows users to color the images. I have
I'm developing an app which downloads a json objects into database,this is done so
I'm developing an app which has a large amount of related form data to

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.