I am working on a camera application. For first time if I capture image its working fine but if I take a picture again its throwing a error
ERROR/dalvikvm-heap(2398): 10077696-byte external allocation too large for this process." VM won't let us allocate 10077696 bytes" and finally"05-02 05:35:38.390: ERROR/AndroidRuntime(2398): FATAL EXCEPTION: main 05-02 05:35:38.390: ERROR/AndroidRuntime(2398): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
and application force closes..how to handle this how to clear heap and vm? please help.. Thanks in advance..
I found the answer.
I used the following code:
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false; //Disable Dithering mode
bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
bfOptions.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
bfOptions.inTempStorage=new byte[32 * 1024];
CameraTricks.SdCardImage= BitmapFactory.decodeFile(CameraTricks.yu,bfOptions);
CameraTricks.yu is my path to bitmap
You don't. You can soft reset the device, but I doubt that will do any good. Android's garbage collector should take care of it.
Most probably, your app is using too much memory for some operation. You can use DDMS to check memory consumption (read about it here).
You can read about similar issues in all these links:
It looks like a common theme is the loading of several large images. Make sure you don't keep references to images (or any other large object) you don't use any more, so the garbage collector can recover that memory. Use Bitamp.recycle()
, for example.
Lastly, make sure you read the article Avoiding Memory Leaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With