How to force garbage collection in Java?

后端 未结 22 1860
离开以前
离开以前 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 00:56

    You can trigger a GC from the command line. This is useful for batch/crontab:

    jdk1.7.0/bin/jcmd  GC.run
    

    See :

    • https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html

提交回复
热议问题