5

Is there any way to handle OutOfMemoryException in Android while using Bitmap of large number of pictures. I tried all the solutions given in this site ie(GC, Bitmap.reset()). I just want to know whether any alert can be generated before the heap memory is going to full? so that i can handle it in a different way.

razlebe
7,1546 gold badges45 silver badges57 bronze badges
asked Mar 14, 2011 at 9:14
1
  • 2
    Just a note: never ever catch OutOfMemoryException. That can lead to totally unexpected behaviour and is considered a bad practice. Commented Mar 14, 2011 at 9:24

1 Answer 1

6

In your Activity there is a callback function you can implement to be notified of low memory issues:

http://developer.android.com/reference/android/content/ComponentCallbacks.html#onLowMemory()

@Override
public void onLowMemory() {
 super.onLowMemory();
 // Your memory releasing code
}
answered Mar 14, 2011 at 9:17
Sign up to request clarification or add additional context in comments.

2 Comments

Note this applies to the overall system. It has almost no relation to a single app running out of managed heap space (which is what what cause an OOM).
-1. As fadden pointed out, this method won't get called even if your app is OOM.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.