Catching java.lang.OutOfMemoryError?

前端 未结 14 1690
Happy的楠姐
Happy的楠姐 2020-11-22 06:01

Documentation for java.lang.Error says:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application

14条回答
  •  甜味超标
    2020-11-22 07:03

    I just have a scenario where catching an OutOfMemoryError seems to make sense and seems to work.

    Scenario: in an Android App, I want to display multiple bitmaps in highest possible resolution, and I want to be able to zoom them fluently.

    Because of fluent zooming, I want to have the bitmaps in memory. However, Android has limitations in memory which are device dependent and which are hard to control.

    In this situation, there may be OutOfMemoryError while reading the bitmap. Here, it helps if I catch it and then continue with lower resolution.

提交回复
热议问题