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

后端 未结 21 1698
死守一世寂寞
死守一世寂寞 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:32

    Increasing the heap size is not a "fix" it is a "plaster", 100% temporary. It will crash again in somewhere else. To avoid these issues, write high performance code.

    1. Use local variables wherever possible.
    2. Make sure you select the correct object (EX: Selection between String, StringBuffer and StringBuilder)
    3. Use a good code system for your program(EX: Using static variables VS non static variables)
    4. Other stuff which could work on your code.
    5. Try to move with multy THREADING

提交回复
热议问题