Garbage collection of Composed Objects

前端 未结 5 2246
青春惊慌失措
青春惊慌失措 2021-01-05 11:10

I have two classes

Class A
{
    //constructor
}

Class B
{
    private A a;

    public B()
    {
        a = new A();
    }
}

Suppose I u

5条回答
  •  不知归路
    2021-01-05 11:15

    Object A will also become eligible garbage collection as soon as you set ObjectB to null (* condition is ObjectA is not referred by any other live object). This condition is known as "Island of Isolation".

    Here is a nice explanation of this situation. (Here is one more explanation from SCJP book)

提交回复
热议问题