When does System.gc() do something?

后端 未结 16 1936
傲寒
傲寒 2020-11-22 05:02

I know that garbage collection is automated in Java. But I understood that if you call System.gc() in your code that the JVM may or may not decide to perform ga

16条回答
  •  一生所求
    2020-11-22 05:55

    You need to be very careful if you call System.gc(). Calling it can add unnecessary performance issues to your application, and it is not guaranteed to actually perform a collection. It is actually possible to disable explicit System.gc() via the java argument -XX:+DisableExplicitGC.

    I'd highly recommend reading through the documents available at Java HotSpot Garbage Collection for more in depth details about garbage collection.

提交回复
热议问题