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

  • Home
  • SEARCH
  • 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 6101611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:31:10+00:00 2026-05-23T13:31:10+00:00

How Do You Force A NinePatchDrawable to release the BitMap bytes it parsed out

  • 0

How Do You Force A NinePatchDrawable to release the BitMap bytes it parsed out of ‘res’?


As an Android developer I face pressure to control memory utilization in my games.

I work to control memory utilization by releasing resources as quickly as I can after they are no longer used. To this end, I maintain a list of all loaded resources and purge / release them from memory as soon as I am done with them.

My application uses a number of different types of graphical resources

  • BitMap
  • BitMapDrawable
  • Drawable
  • NinePatchDrawable

How do I release these objects right now?

  • BitMap : I use the “recycle()” method
  • BitMapDrawable : I use the “getBitMap().recycle()” method
  • Drawable : I set these to null (not working)
  • NinePatchDrawable : I set these to null (not working)

What have you tried?

  • You cannot “getBitmap()” a NinePatchDrawable
  • You cannot convert a NinePatchDrawable to a BitMapDrawable (even if they are both Bitmap based Drawables)
  • There seems to be a way to parse the PNG yourself, feeding the bytes into NinePathDrawable yourself — this might get me to a point where I can just “recycle()” the underlying BitMap myself, but that seems like I’m reinventing the wheel (http://code.google.com/p/android/issues/detail?id=13542)

My Current Rules:

  • Never use @drawable/ in XML
  • Never android:background in XML
  • Never android:src in XML
  • 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-23T13:31:10+00:00Added an answer on May 23, 2026 at 1:31 pm

    To be able to use: @drawable/, android:background, android:src in xml, you can always use custom classes.

    So instead of
    <ImageView android:src="@drawable/bg" />
    you can use:
    <com.myPackage.CustomImageView android:src="@drawable/bg" />

    Than in the CustomImageView in the constructor you can get the references to your xml attributes:

        
    private Drawable bg2;
    private Drawable bg1;
    public void CustomImageView(Context context, Attrs attrs)
    {
        super(context, attrs);
    
        // Use this to get references to your xml attributes
        int resourceId = attrs.getAttributeResourceValue("android", "src", 0);
        bg1 = getResources().getDrawable(resourceId);
    
        // Or for the 'background' attribute
        resourceid = attrs.getAttributeResourceValue("android", "background", 0);
        bg2 = getResources().getDrawable(resourceId);
    
        // Now you can recycle() your 'bg' whenever you're done
    }
    

    This way, you can extract references from your xml. And recycle() them when you think it’s appropriate

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

Sidebar

Related Questions

I know how to force check out for Lists Libraries. But I am not
I find the force close Report option very useful as a developer- the stack
how can I force Android to clear it's dialog cache when screen orientation changes?
Does Google force employees who have offers from Facebook to leave immediately?
Does Microsoft force an update down to all of its users of windows-update? Is
I want to force the current execution line to a specific line in the
How do I force Python's print function to flush the buffered output to the
I'm looking to force my application to shut down, and return an Exit code.
How can I force the input's onchange script to run before the RangeValidator's script?
Sometimes software installers force you to scroll to the end of the EULA before

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.