Android 应用程序因图像崩溃
我正在开发一个 Android 应用程序,它可以从相机或图书馆拍摄照片并对其进行一些处理。问题是,在使用一段时间后,应用程序崩溃了。我已经尝试进行我能想到的所有可能的优化,例如在可能的情况下调用 gc,在离开活动时清空图像,甚至从缓存中删除活动。但我仍然遇到内存错误并且应用程序崩溃。
关于如何避免此类错误有什么建议吗?或者甚至如何有效地从drawables文件夹加载图像。或者有什么有效的方法可以在活动更改时抛出所有不需要的对象,以便仅使用活动活动所需的内存?
I'm developing an android app that takes photos from camera or from library and does some stuff on them. The point is that after some use the application crashes. I have tried to make every possible optimization I could think of, ex call gc when possible, null the images when I leave an activity and even remove activities from the cache. But I still get out of memory errors and the app crashes.
Any suggestions on how to avoid such errors? Or even how to efficiently load images from drawables folder . Or any efficient way to throw all not needed objects when the activity changes so as to only use the needed memory for the active activity??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,最终将它们追踪到特定的图像。在我的 400 张图片中,有 3 张非常大(文件大小方面)。所以我会检查您的所有图像是否具有相似的文件大小(通常它与图像大小直接相关)
并且位图不是很大吗?你的平均图片有多大?
i had similar problems and ended up tracking them down to particular images. out of my 400 images there where three that where huge (file size wise). so i would check that all of your images have similar file size (usually it is directly correlated with image size)
also aren't bitmaps pretty big? how big is your average picture?
您管理 Bitmap 对象吗?如果是这样,你必须调用 Bitmap.recycle() 方法。
Bitmap.recycle() API 文档
Did you manage Bitmap objects? If so, you have to call Bitmap.recycle() method.
Bitmap.recycle() API documentation