Janki Shah wrote:At #1 no object is eligible for GC. because, go() method has not finished and pudding object has also reference to this(which is new Mian at line 13).
At #2 two objects are eligible for GC. because, method is finished and there is no reference to pudding created at line 16 and also no reference variable to new Main() created at line 13.
Please correct me if I am wrong.
You are right