How to force garbage collection in Java?

后端 未结 22 1405
离开以前
离开以前 2020-11-22 00:31

Is it possible to force garbage collection in Java, even if it is tricky to do? I know about System.gc(); and Runtime.gc(); but they only suggest t

22条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 01:12

    It would be better if you would describe the reason why you need garbage collection. If you are using SWT, you can dispose resources such as Image and Font to free memory. For instance:

    Image img = new Image(Display.getDefault(), 16, 16);
    img.dispose();
    

    There are also tools to determine undisposed resources.

提交回复
热议问题