When does System.gc() do something?

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

    If you use direct memory buffers, the JVM doesn't run the GC for you even if you are running low on direct memory.

    If you call ByteBuffer.allocateDirect() and you get an OutOfMemoryError you can find this call is fine after triggering a GC manually.

提交回复
热议问题