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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:50+00:00 2026-05-26T20:08:50+00:00

I have a problem with a ListActivity, it loads a search result, 5 items

  • 0

I have a problem with a ListActivity, it loads a search result, 5 items at a time, and when it reach about 45 items, it throws an out of memory exception.

I load images from web server asyncronically. If I comment this, i can scroll to the bottom of the list (aprox 58 items) without problem. I Know i should call bitmap.Recycle() to gc the bitmaps i no longer use, but I dont find when i should call that.

class ImageLoadingTask extends AsyncTask<String, Void, Bitmap> {
        private final WeakReference<ImageView>  imageViewReference;
        String                                  url;

        public ImageLoadingTask(ImageView imageView) {
            imageViewReference = new WeakReference<ImageView>(imageView);
            imageViewReference.get().setImageDrawable(null);
        }

        @Override
        protected void onPostExecute(Bitmap result) {
            if (isCancelled()) {
                result = null;
            }
            if (imageViewReference != null) {
                ImageView imageView = imageViewReference.get();
                if (imageView != null) {                        
                    imageView.setImageBitmap(result);
                    //result.recycle();
                }
            }
        }

        @Override
        protected void onPreExecute() {
            if (imageViewReference != null) {
                ImageView imageView = imageViewReference.get();
                if (imageView != null) {
                    imageView.setImageResource(R.drawable.icon);
                }
            }
        }

        @Override
        protected Bitmap doInBackground(String... params) {
            url = params[0];
            return Application.get(getContext()).loadBitmap(url);
        }
    }

As you see in the onPostExecute method. if I call recycle right after the image is asigned to the imageview, it thros an exeption of tying to use a recycled image.

Anybody could help?

Thanks in advance, and sorry for my english 😛

  • 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-26T20:08:50+00:00Added an answer on May 26, 2026 at 8:08 pm

    I suggest lazy loading the images. Which means downloading them to the SD card first and then loading them as needed into the list. Checkout this stackoverflow post for an extensive discussion on how to do this.

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

Sidebar

Related Questions

I have a problem with my ListActivity, i use a thread to show a
I have created a listActivity with my own ListAdapter. The problem is that the
I have a problem my ListActivity . I have this xml: <LinearLayout> <ListView android:id=@android:id/list
I have a problem with my ListActivity , i hope someone can help me.
Summery of problem:- I have classes named AttachPicture which extends the ListActivity and another
My problem is that I cannot reach ListView in Java. I'm using a ListActivity.
I have a problem understanding why is my ListActivity and its corresponding listView empty
I'm having the following problem: I have a ListActivity, its ListView is composed by
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names

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.