How to deal with “java.lang.OutOfMemoryError: Java heap space” error?

后端 未结 21 1693
死守一世寂寞
死守一世寂寞 2020-11-21 04:49

I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryEr

21条回答
  •  名媛妹妹
    2020-11-21 05:17

    I would like to add recommendations from oracle trouble shooting article.

    Exception in thread thread_name: java.lang.OutOfMemoryError: Java heap space

    The detail message Java heap space indicates object could not be allocated in the Java heap. This error does not necessarily imply a memory leak

    Possible causes:

    1. Simple configuration issue, where the specified heap size is insufficient for the application.

    2. Application is unintentionally holding references to objects, and this prevents the objects from being garbage collected.

    3. Excessive use of finalizers.

    One other potential source of this error arises with applications that make excessive use of finalizers. If a class has a finalize method, then objects of that type do not have their space reclaimed at garbage collection time

    After garbage collection, the objects are queued for finalization, which occurs at a later time. finalizers are executed by a daemon thread that services the finalization queue. If the finalizer thread cannot keep up with the finalization queue, then the Java heap could fill up and this type of OutOfMemoryError exception would be thrown.

    One scenario that can cause this situation is when an application creates high-priority threads that cause the finalization queue to increase at a rate that is faster than the rate at which the finalizer thread is servicing that queue.

提交回复
热议问题