我正在开发相机应用程序。如果我第一次拍摄图像,它工作正常,但如果我再次拍摄照片,它会抛出错误
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
应用程序强制关闭..如何处理这个如何清除堆和虚拟机? 请帮忙.. 提前致谢..
最佳答案
我找到了答案。
我使用了以下代码:
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
关于android - 如何清除堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5853804/