Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity's public void onLowMemory() method does not called by android framework when system runs OutOfMenory

Tags:

android

I create bitmap drawables from large images and OutOfMemory error occures at that time. Activity.onLowMemory() method should be called but actually it is not called by framework.

Is there any solution of this, or is there any other way to capture OutOfMemory error in android?

like image 228
Hardik Muliya Avatar asked May 07 '12 14:05

Hardik Muliya


1 Answers

That is not how onLowMemory works. It will be called when the whole System runs low on memory, not your App, so you can't exactly avoid OOMs with it. More Details here.
Also see a blog post from Romain Guy for some more Info about memory leaks: links

At least there are hundreds of Questions how to handle Bitmaps here on Stackoverflow:

Android Bitmap Memory Leak, what to do more
Bitmap, Bitmap.recycle(), WeakReferences, and Garbage Collection
Android custom view Bitmap memory leak

like image 108
Thommy Avatar answered Sep 30 '22 04:09

Thommy