When is garbage collector used in java?

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

    The JVM and java specs don't say anything about when garbage collection occurs, so its entirely up to the JVM implementors what policies they wish to use. Each JVM should probably have some documention about how it handles GC.

    In general though, most JVMs will trigger GC when a memory allocation pushes the total amount of allocated memory above some threshold. There may be mulitple levels of gc (full vs partial/generational) that occur at different thresholds.

提交回复
热议问题