How to clear a bunch?

I am working on a camera application. The first time, if I captured the image, it worked fine, but if I take the picture again, it will throw an error

ERROR / dalvikvm-heap (2398): the external allocation of 10077696 bytes is too large for this process. "VM will not allow us to 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 the power of the application closes. How to handle this, how to clear heap and vm? please help .. Thanks in advance.

+6
source share
2 answers

I have 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 
+4
source

Not. You can gently reset the device, but I doubt it will be beneficial. Android scavenger needs to take care of this.

Your application most likely uses 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 of these links:

It seems like a common theme is loading a few large images. Make sure that you do not store links to images (or any other large objects) that you no longer use, so the garbage collector can recover this memory. Use Bitamp.recycle() , for example.

Finally, make sure you read the article Avoid Memory Leaks .

+1
source

Source: https://habr.com/ru/post/887100/


All Articles