Question: 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..

Answer: 
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](http://developer.android.com/guide/developing/debugging/ddms.html)).

You can read about similar issues in all these links:

* <http://markmail.org/message/smg7pog5tz25p7w5>
* [External allocation too large for this process in Android](https://stackoverflow.com/questions/4193917/external-allocation-too-large-for-this-process-in-android)
* [Strange out of memory issue while loading an image to a Bitmap object](https://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue)
* <http://code.google.com/p/android/issues/detail?id=2822>
* [Bitmap, Bitmap.recycle(), WeakReferences, and Garbage Collection](https://stackoverflow.com/questions/4959485/android-bitmap-bitmap-recycle-weakreference-and-garbage-collector)
* [How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size)](https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap-s)

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](http://developer.android.com/resources/articles/avoiding-memory-leaks.html).