For example, I have this code:
var objectA = {};
var objectB = {};
objectA.pointer = objectB;
objectB.pointer = objectA;
objectA = null;
objectB = null;
I assume that after last two statements, there is no reference to objects originally assigned to objectA and objectB variables. But according to the technical literature, the reference for those objects still exists. Why ? Does objectA.pointer reference or objectB.pointer reference still exists even the objectA and objectB are set to null ?
                        
Yes.
Maybe some ASCII art helps. After performing
the environment contains two variables (
objectAandobjectA) that hold references to two objects (denoted asref:XXX):After adding properties to the objets,
both objects have a
pointerproperty each contain a reference to the other object:As you can se see, there is no relation between a
pointerproperty and theobjectAandobjectBvariables.objectA.pointerdoesn't refer to the variableobjectB, it got a copy of its value (ref:456), a reference to the object.After setting both variables to
null,the environment looks like this:
The
pointerproperties still hold the references to the other object. Replacing the values ofobjectAandobjectBdidn't change that.