How to know about OutOfMemory or StackOverflow errors ahead of time

前端 未结 11 1742
余生分开走
余生分开走 2021-02-15 17:10

In Java, is there a way to know that a StackOverflow error or OutOfMemory exception may happen soon?

The OutOfMemory exception m

11条回答
  •  野性不改
    2021-02-15 17:26

    You can anticipate out-of-memory conditions with Runtime.freeMemory() and Runtime.maxMemory(). Most times it'll be hard recovering gracefully, but I leave that to you.

提交回复
热议问题