When does System.gc() do something?

后端 未结 16 1912
傲寒
傲寒 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:40

    Most JVMs will kick off a GC (depending on the -XX:DiableExplicitGC and -XX:+ExplicitGCInvokesConcurrent switch). But the specification is just less well defined in order to allow better implementations later on.

    The spec needs clarification: Bug #6668279: (spec) System.gc() should indicate that we don't recommend use and don't guarantee behaviour

    Internally the gc method is used by RMI and NIO, and they require synchronous execution, which: this is currently in discussion:

    Bug #5025281: Allow System.gc() to trigger concurrent (not stop-the-world) full collections

提交回复
热议问题