Mihai1977 wrote:Hi,
Line 1: object "no1" is created, "obj" points to object "no1";
Line 2: object "NewClass" is created, "tc" points to object "NewClass";
Line 3: reference "o" point also to Object "no1";
Correct.
Line 4: object "no2" is created, "obj" now points to "no2", "s" still points to object "no1";
s exists only inside the method doSomething. Once the method returns there is no "s" anymore at line 4.
But o, which is a instance member still points to object no1.
Line 5: "obj" points to null, so "no2" is ready for garbage collector, "s" still points to object "no1";
Again, there is no s at this point. But o, which is a instance member still points to object no1.
Line 6: a new reference "o" points again to object "no1"???
o is an instance member. So there is only one o per NewClass object. Since doSomething is being called on the same NewClass object, the same o will now be changed to point to null (because null is being passed to doSomething).
HTH,
Paul.