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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:28:17+00:00 2026-05-26T06:28:17+00:00

I have an app which downloads images from a server, stores them on the

  • 0

I have an app which downloads images from a server, stores them on the sd card and then displays them to the user as a slideshow. The app has a number of different slideshows that the user can view. My problem is that after I view a few galleries I get an out of memory error. I have done quite a bit of Googling, and have read Romain Guy’s Avoiding Memory Leaks article about 20 times. I have tried to replicate his unbindDrawables() method but the but removeAllViews() cannot be called on Gallery objects. I have also tried to call recycle() on all the bitmaps I can but when I do it on the bitmap within the adapter, the app throws an error as soon as I open an image gallery.
I have also tried recoding the slideshow so that I create all the bitmaps outside the adapter and then pass them in as an array — this allows me to loop through my bitmap array and call recycle() on each one in the onDestroy method in the slideshow activity — but this actually seems to make the leak worse not better.

Here is the code for my Slideshow activity:

public class Slideshow extends Activity {
    static String galleryId;
    public static final int MSG_DOWNLOADED = 0;
    static  Handler handler;
    static Gallery g;
    static ArrayList<String> filePaths;
    static String subFolder;
    static ArrayList<String>  imageToGet;
    static LinearLayout pb;
    static boolean firstTime = true;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.slideshow);
            Context context = getApplicationContext();


            Bundle extras = getIntent().getExtras();

            if(extras != null){
            galleryId = extras.getString("galleryId");
            }
            pb = (LinearLayout) findViewById(R.id.progress); 
             handler = new Handler(){
                    @Override
                    public void handleMessage(Message msg){
                        switch (msg.what){
                        case MSG_DOWNLOADED:
                            g.setAdapter(new SlideshowAdapter(getApplicationContext(), R.id.gallery, filePaths));
                            pb.setVisibility(8);
                            if(firstTime){
                            Thread images = new Thread(){
                                public void run(){
                                    ImageGallery gallery = XMLParser.getGalleryById(galleryId, false, getApplicationContext());
                                    ArrayList<String> imageURLs = gallery.getImageURLs();
                                    String subFolder = "gallery"+galleryId+"/";
                                    getImages(imageURLs, subFolder, false);
                                }
                            };
                            images.start();
                            firstTime = false;
                            }
                            break;
                        }
                    }
                };
            ImageGallery gallery = XMLParser.getGalleryById(galleryId, false, context);
            filePaths = gallery.getFilePaths();
            ArrayList<String> imageURLs = gallery.getImageURLs();
            subFolder = "gallery"+galleryId+"/";
            g = (Gallery) findViewById(R.id.gallery);
            if(filePaths.size() > 0){
            String filePath = filePaths.get(0);
            String url = imageURLs.get(0);
            imageToGet = new ArrayList<String>();
            imageToGet.add(url);

            if(filePaths.size() == 1 ){
                File file = new File(filePath);
                if(!file.exists()){
                    Thread getFirstImage = new Thread(){
                        public void  run(){
                            Log.d("ClubSlideshow getting only image", ""+imageToGet.get(0));
                            getImages(imageToGet, subFolder, false);
                            handler.sendEmptyMessage(MSG_DOWNLOADED);
                        }
                    };
                    getFirstImage.start();
                }

            }else if(filePaths.size()>1){
                String filePath2 = filePaths.get(1);
                String url2 = imageURLs.get(1);
                File file = new File(filePath);
                File file2 = new File(filePath2);
                imageToGet.add(url2);
                if(!file.exists()||!file2.exists()){
                    Thread getFirstImage = new Thread(){
                        public void  run(){
                            getImages(imageToGet, subFolder, false);
                            handler.sendEmptyMessage(MSG_DOWNLOADED);
                        }
                    };
                    getFirstImage.start();
                }

            }
            }


    }

    public void getImages(ArrayList<String> imageURLs, String subFolder, boolean force){
        DataCache.downloadFromUrlArray(imageURLs, subFolder, force, getApplicationContext());
    }

    public class ImageThread implements Runnable{
        public ImageThread(ArrayList<String> imageURLs, String subFolder, Boolean force){
            getImages(imageURLs, subFolder, force);
        }

        public void run(){

        }
    }

    @Override
    protected void onDestroy(){
        super.onDestroy();
        g.setAdapter(null);
    }

}

And here is my code for my SlideshowAdapter class:

public class SlideshowAdapter extends ArrayAdapter<String> {
    int mGalleryItemBackground;
    private Context mContext;
    private ArrayList<String> images = new ArrayList<String>();
    Bitmap bMap;
    String filePath;
    File file;
    ImageView i;

    public SlideshowAdapter(Context c, int resourceId, ArrayList<String> objects){
        super(c, resourceId, objects);
        this.mContext = c;
        this.images = objects;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView !=null){
            i = (ImageView) convertView;
        }else{
            i = new ImageView(mContext);
        }

        filePath = mContext.getFilesDir()+"/"+images.get(position);

        file = new File(filePath);
        if(file.exists()){
            bMap = BitmapFactory.decodeFile(filePath);
            i.setImageBitmap(bMap);
        }

        i.setScaleType(ImageView.ScaleType.FIT_CENTER);

        return i;
    }

}

Can anyone see what might be causing my memory issues?

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

    you may try using scaledBitmap to reduce the memory usage

    if(file.exists()){ 
                bMap = BitmapFactory.decodeFile(filePath); 
                i.setImageBitmap(bMap); 
            } 
    

    to

    if(file.exists()){ 
                bMap = BitmapFactory.decodeFile(filePath); 
                bMap = Bitmap.createScaledBitmap(bMap, 100, 100, true);
                i.setImageBitmap(bMap); 
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small Silverlight app which downloads all of the images and text
I have a paid application on the App Store, which when a user downloads,
I have an app which contain some images in res/drawable/ and shows them in
In my app, the activity starts a thread which download images from server. There
I have a little Updater in my mac app, which automatically downloads a dmg-file
I have a app which will download a file from web. The download action
I have an app which has a map and some POI on it. I'm
I have an app which access an app folder on a per user basis.
I have an app which requires downloading image asynchronously in base64 encoded string(server is
I have an app with a list view that downloads images on the fly.

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.