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
var objectA = {}; var objectB = {};
the environment contains two variables (objectA and objectA) that hold references to two objects (denoted as ref:XXX):
+--------------+ +-------+---------+ +--->| Object#123 | |objectA|ref:123 *+--+ +--------------+ +-------+---------+ |objectB|ref:456 *+--+ +--------------+ +-------+---------+ +--->| Object#456 | +--------------+
After adding properties to the objets,
objectA.pointer = objectB; objectB.pointer = objectA;
both objects have a pointer property each contain a reference to the other object:
+-----------------+ | Object#123 | +--->+-------+---------+<----+ +-------+---------+ | |pointer|ref:456 *+---+ | |objectA|ref:123 *+-+ +-------+---------+ | | +-------+---------+ | | |objectB|ref:456 *+-+ +-----------------+ | | +-------+---------+ | | Object#456 | | | +--->+-------+---------+<--+ | |pointer|ref:123 *+-----+ +-------+---------+
As you can se see, there is no relation between a pointer property and the objectA and objectB variables. objectA.pointer doesn't refer to the variable objectB, it got a copy of its value (ref:456), a reference to the object.
After setting both variables to null,
objectA = null; objectB = null;
the environment looks like this:
+-----------------+ | Object#123 | +-------+---------+<----+ +-------+---------+ |pointer|ref:456 *+---+ | |objectA| null | +-------+---------+ | | +-------+---------+ | | |objectB| null | +-----------------+ | | +-------+---------+ | Object#456 | | | +-------+---------+<--+ | |pointer|ref:123 *+-----+ +-------+---------+
The pointer properties still hold the references to the other object. Replacing the values of objectA and objectB didn't change that.
objectA = null;only sets the value of the variableobjectAtonull. It does not change the value of the propertyobjectB.pointer.objectB.pointerstill refers to an object. Variables / properties are just containers for values. An assignments "copies" the value and now two containers contain the "same" value (each has their own copy). Replacing the value in one of the containers doesn't magically replace the value in another container.objectAtonulldoes not changeobjectB.pointerobjectB.pointer = objectA;then you are copying the content from one container to another. In other wordsobjectB.pointerdoes not refer to the containerobjectAbut to the value that it has/had. Later when you doobjectA = null;you are changing the content of containerobjectA. That has no impact onobjectB.pointer. Here is a simpler example:var foo = 42; var bar = foo; foo = 0;.barhas still the value42even though I setfooto0. Changing the value offoohas no impact onbar.