What triggers the java Garbage Collector

前端 未结 3 1545
不知归路
不知归路 2021-01-28 05:20

I am a little confused to how garbage collection in Java works.

I get that an object becomes eligible for garbage collection when there are no more live references to it

3条回答
  •  無奈伤痛
    2021-01-28 05:59

    It does not matter for the garbage collection of Node A if Node B has any other references to it. If Node A has no references to it, it will be garbage collected. Node B will stay, as it still has live references.

    Basically, every object that has no live references to it will be collected. Any objects contained in those objects will be subject to the same mechanism, if there are no other references to them, they will also be garbage collected. If there are live references from other objects, they will stay.

提交回复
热议问题