如何处理OutOfMemoryError [英] How to handle OutOfMemoryError

查看:91
本文介绍了如何处理OutOfMemoryError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有照片,视频等.对于图像,我已完成缩放,但有时会得到OutOfMemoryError.如何有效地处理错误?

In my application I have photos, videos, etc.. In the case of images, I have done scaling, but sometimes I get an OutOfMemoryError. How can I handle the error efficiently?

推荐答案

在尝试加载图像之前,请检查图像大小是否小于可用内存.因此,处理OutOfMemoryException的最有效方法是构建应用程序,以使其永远不会尝试将大量数据加载到内存中以避免这种异常.

Check that the image size is smaller than the available memory before attempting to load it. So the most efficient way to handle OutOfMemoryException is to architecture your application in such a way that it never attempts to load lots of data into memory in order to avoid the exception.

这篇关于如何处理OutOfMemoryError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆