在 Android 中更改 Activity 或创建 Bitmap 对象时,我在 Android 中捕获内存不足的异常,我应该做什么来完成当前 Activity 或执行其他操作?由于Java有垃圾收集器,所以我想我不必手动删除对象。
try {
// done something that causing memory leak
} catch (OutOfMemoryError e) {
// what should I do here
}
如有任何建议,我们将不胜感激。
最佳答案
来自错误
的JavaDoc:
An
Error
is a subclass ofThrowable
that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.
当发生OutOfMemoryError
时,损坏已经造成。您应该识别并解决应用程序中的问题,而不是捕获此错误。
当您创建位图对象时,可能的原因可能是该位图的大小太大,或者您创建了太多位图。
关于java - Android内存泄漏异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30077539/