When is garbage collector used in java?

后端 未结 4 1900
一个人的身影
一个人的身影 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:37

    In the older days garbage collector were empirical in nature. At some set interval or based on certain condition they would kick in and examine each of the object.

    Modern days collectors are smarter in the sense that they differentiate based on the fact that objects are different lifespan. The objects are differentiated between young generation objects and tenured generation objects.

    Memory is managed in pools according to generation. Whenever the young generation memory pool is filled, a minor collection happens. The surviving objects are moved to tenured generation memory pool. When the tenured generation memory pool gets filled a major collection happens. A third generation is kept which is known as permanent generation and may contain objects defining classes and methods.

提交回复
热议问题