How to force garbage collection in Java?

后端 未结 22 1565
离开以前
离开以前 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:02

    You can try using Runtime.getRuntime().gc() or use utility method System.gc() Note: These methods do not ensure GC. And their scope should be limited to JVM rather than programmatically handling it in your application.

提交回复
热议问题