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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:11:02+00:00 2026-05-18T06:11:02+00:00

I have 3 image resources in my app. Loading and displaying any one of

  • 0

I have 3 image resources in my app.
Loading and displaying any one of them in an ImageView goes smoothly.
But when I remove the displayed ImageView from the layout, null it and
add a new image, things get weird.

Either the process crashes completely (signal 11) when I try
calling .recycle() on the old bitmap or I get an OutOfMemoryError in
case I don’t use recycle.

This only happens on API Levels below 8, so my guess is that bugs with
GC on the native heap are causing it and these bugs were fixed on
2.2. However, since 2.1 is currently the most common version out
there I need a workaround…

Again, there shouldn’t be a lack of memory for the native heap. I hold
only 1 image at a time and null the previous so the GC should be able
to retrieve the heap space (like happens on 2.2).

I’ve created a very small sample app which can be downloaded from
here:
http://www.4shared.com/file/QqHrhJLR/BitmapRecycleTest.html

Any suggestions will be appreciated.

  • 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-18T06:11:03+00:00Added an answer on May 18, 2026 at 6:11 am

    I’ve taken a look. I get the signal 11 on a Nexus One running 2.2.1. The callstack is this:

    I/DEBUG   (   56):          #00  pc 0000c584  /system/lib/libc.so
    I/DEBUG   (   56):          #01  pc 0000cd2e  /system/lib/libc.so
    I/DEBUG   (   56):          #02  pc 0002c5dc  /system/lib/libskia.so
    I/DEBUG   (   56):          #03  pc 00068108  /system/lib/libskia.so
    I/DEBUG   (   56):          #04  pc 00063a8c  /system/lib/libskia.so
    I/DEBUG   (   56):          #05  pc 0004cefc  /system/lib/libandroid_runtime.so
    I/DEBUG   (   56):          #06  pc 00016e34  /system/lib/libdvm.so
    I/DEBUG   (   56):          #07  pc 000452c4  /system/lib/libdvm.so
    I/DEBUG   (   56):          #08  pc 0001bd98  /system/lib/libdvm.so
    ...
    

    Clearly there’s a bug in Android here, but it seems to be avoidable.

    Don’t use your BitmapResource class… you should explicitly recycle() your bitmaps the moment you don’t need them any more. I changed your DrawView constructor to this:

    public DrawView(Context context, int resId) {
        super(context);
        setImageResource(resId);
    }
    

    Since your images are so large – 7MB decompressed! – I also added a System.gc() after the previous image is removed. buttonClickHandler now looks like this:

    public void buttonClickHandler(View v) {
        Object tagObj = mSwitchButton.getTag();
        if (tagObj != null && tagObj instanceof ImageView) {
            ImageView iv = (ImageView)tagObj;
            iv.setImageBitmap(null);
                mMainLayout.removeView(iv);
            System.gc();
        }
    
        addNewViewToLayout(mMainLayout);
    }
    

    With these changes your app runs fine for me.

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

Sidebar

Related Questions

I have a simple app (this is my first one) which loads an image
In our iOS app we have close to a hundred image files in resources
I have an application with several activities and a lot of image resources. I
I have an image that I have in my bundle resources that I need
I have some static resources (images and HTML files) that will be localized. One
I'd like to have a splash screen while loading resources (images and sounds). How
I have this problem... I need to load an image from the resources of
I have a resources web app, which only has static content, such as images,
I have developed application in Android and designed one splash screen image of size
I have about 500 images as resources in my app. First, is that a

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.