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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:24:45+00:00 2026-05-25T22:24:45+00:00

My activity simply displays an image: public class PhotoFrameActivity extends Activity { @Override public

  • 0

My activity simply displays an image:

public class PhotoFrameActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        File externalStorageDir = Environment.getExternalStorageDirectory();
        File picturesDir = new File(externalStorageDir, "DCIM/Camera");
        File[] files = picturesDir.listFiles(new FilenameFilter(){
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".jpg");
            }});
        List<File> photoFiles = Arrays.asList(files);
        if (!photoFiles.isEmpty()) {
            try {
                Bitmap currentPhoto = BitmapFactory.decodeStream(new FileInputStream(photoFiles.get(3)));
                ImageView view = (ImageView) findViewById(R.id.photo);
                view.setImageBitmap(currentPhoto);
            } catch (FileNotFoundException e) {
                Log.e("SHOWPIC", "Could not find photo", e);
            }
        }
    }

}

If the activity is restarted, memory is not reclaimed. i.e. if I turn the phone twice I get the following FC:

10-01 17:29:06.011: ERROR/AndroidRuntime(8446): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
10-01 17:29:06.011: ERROR/AndroidRuntime(8446):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
10-01 17:29:06.011: ERROR/AndroidRuntime(8446):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
10-01 17:29:06.011: ERROR/AndroidRuntime(8446):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
10-01 17:29:06.011: ERROR/AndroidRuntime(8446):     at net.badgerhunt.photoframe.PhotoFrameActivity.onCreate(PhotoFrameActivity.java:34)

How am I leaking?

  • 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-25T22:24:45+00:00Added an answer on May 25, 2026 at 10:24 pm

    As Yashwanth Kumar suggested, it’s NOT due to your image being too large. Even if you reduce the sample size you will still (eventually) get an OOM. The memory leak you have will not get fixed by reducing sample size.

    It seems you have a memory leak. Either you can go on a memory leak hunt and try to find the root of your problem, or you could just override the ondestroy method of your activity and do

     @Override
        protected void onDestroy() {
            super.onDestroy();
        view.setImageBitmap(null);
        currentPhoto.recycle();
        }
    

    This will make sure your bitmap gets recycled and the memory gets freed when you activity is being destroyed(as in the case of orientation switch). I would however advice you to watch this video and eventually finding the root to your leak: http://www.google.com/events/io/2011/sessions/memory-management-for-android-apps.html

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

Sidebar

Related Questions

I have a very simple activity just to show the preference fragment: public class
I have an Activity in my app that simply displays some results from a
I have an Activity, which simply consists in listing Pair<String, String> objects. I have
I have an Activity which uses a Fragment . I simply want to pass
I am creating an activity that displays 9 images in a GridView. I want
I am curious what is the best way to design an activity that simply
This is my code and I want the save image button to simply save
I have two activities: one displays an image and a button, the other displays
I created very simple activity that displays hello world and a button labled TEST,
My Android app has a ContactsList activity in which I simply display a list

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.