相关疑难解决方法(0)

捕获java.lang.OutOfMemoryError?

文档java.lang.Error说:

Error是Throwable的子类,表示合理的应用程序不应该尝试捕获的严重问题

但是作为java.lang.Error子类java.lang.Throwable,我可以捕获这种类型的Throwable.

我明白为什么抓住这种例外不是一个好主意.据我所知,如果我们决定捕获它,catch处理程序不应该自己分配任何内存.否则OutOfMemoryError将再次抛出.

所以,我的问题是:

  1. 捕获时是否有任何真实的单词场景java.lang.OutOfMemoryError可能是一个好主意?
  2. 如果我们决定捕获java.lang.OutOfMemoryError,我们怎么能确定catch处理程序本身不分配任何内存(任何工具或最佳实践)?

java try-catch out-of-memory

97
推荐指数
8
解决办法
8万
查看次数

在循环中创建位图时出现内存溢出异常

我必须从许多图像中导入大量的图像裁剪,这些图像都已准备好存储在我的数据库中.我每次尝试使用语句并处理我的位图对象.但我仍然得到一个内存溢出异常,我的系统内存不足.

以下是我正在做的一些示例代码.

public void CropImage(List<ImageClass> data)
{
    foreach (var obj in data)
    {
        //I have a data base method that returns a data object that 
        //contains the file bytes of the image id in data: 'file'
        //My List<ImageClass> data contains an ID of the original image
        //start x,y coords for the upper left corner of the rectangle,
        //and the width and height of the rectangle.

        Image img = Image.FromStream(new MemoryStream(file.Data));
        Bitmap bmp = new Bitmap((Bitmap)img);
        Rectangle cropArea = new Rectangle(obj.x_coordinate, …
Run Code Online (Sandbox Code Playgroud)

c# memory imaging bitmap overflow

1
推荐指数
1
解决办法
1625
查看次数

标签 统计

bitmap ×1

c# ×1

imaging ×1

java ×1

memory ×1

out-of-memory ×1

overflow ×1

try-catch ×1