8
votes

Our application uses a lot of bitmaps. It works fine for example on G1, XOOM. But on HTC Desire there is an OutOfMemory error. In code we use try/catch(OutOfMemoryError e) and all devices(except Desire) throw exception, but HTC just kills the application without OOM exception. We restricted the memory for bitmaps to 12 Mb and it seemed that this solution fixed the problem, but customer still has problem on HTC Desire HD. There is OOM even with 12 Mb restriction. Here are the logs:

06-07 12:03:43.978 E/dalvikvm-heap( 29616):1140128-byte external allocation too large for this process. 
06-07 12:03:43.978 E/dalvikvm( 29616):Out of memory: Heap Size=12311KB, Allocated=9420KB, Bitmap Size=12139KB, Limit=21884KB
06-07 12:03:43.978 E/dalvikvm( 29616):Trim info: Footprint=15751KB, Allowed Footprint=15751KB, Trimmed=3440KB
06-07 12:03:43.978 E/GraphicsJNI( 29616):VM won't let us allocate 1140128 bytes

AFAIK there are different heap size limitations for devices(G1: 16mb, Droid: 24 mb, Xoom 48 mb). In my opinion system should give at least 16 mb, but we have OOM with 12mb. My question is: How to find out how many free heap size available for bitmap for Android 2.*? Or please advice how to avoid such problem in other ways. FYI we can't use less bitmaps, especially when it works fine on other devices. Thanks in advance for any help!

2

2 Answers

2
votes

You can try

Runtime.getRuntime().maxMemory();

or Activity's method

getMemoryInfo(ActivityManager.MemoryInfo;

Besides, you can override Activity's

onLowMemory();

method, in which you can handle what will happen when the Activity get's notified of the memory issue, before being shut down. And you should also check this answer from an Android dev on Android/Linux memory.

0
votes

This OutOfMemory exception comes from a memory leak not from the file itself. Are you overriding the activity lifecycle methods like onStop, onResume, onDestroy?