When is garbage collector used in java?

后端 未结 4 1714
一个人的身影
一个人的身影 2021-01-23 15:10

As far as I know GC is used only when JVM needs more memory, but I\'m not sure about it. So, please, someone suggest an answer to this question.

4条回答
  •  失恋的感觉
    2021-01-23 15:45

    Garbage Collection is deliberately vaguely described in the Java Language Specification, to give the JVM implementors best working conditions to provide good garbage collectors.

    Hence garbage collectors and their behaviour are extremely vendor dependent.

    The simplest but least fun is the one that stops the whole program when needing to clean. Others are more sophisticated and run quietly along your program cleaning up as you go more or less aggressively.

    The most fun way to investigate garbage collection is to run jvisualvm in the Sun 6 JDK. It allows you to see many, many internal things many relevant to garbage collection.

    https://visualvm.dev.java.net/monitor_tab.html (but the newest version has plenty more)

提交回复
热议问题