android - 如何清除堆?

标签 android

我正在开发相机应用程序。如果我第一次拍摄图像,它工作正常,但如果我再次拍摄照片,它会抛出错误

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/

相关文章:

Android L setEnterTransition 不工作

java - 更改 Checkbox for Android 的选中和未选中图标

java - Firebase 数据库身份验证注册

java - 今天的日期和旧日期之间的差异计算不正确

android - 应用 ColorFilter/ColorMatrix 将图像完全变白

android - 从 getAdminArea() 获取州缩写;

android - 无法使 roughike 底部栏导航标题居中

android - 在标题栏之后对齐 Imageview

带有 Jedis 的 Android 应用程序

Android MVVM 多 API 调用