I'm new to JavaScript and trying to understand the memory management related to objects using this Mozilla reference: MDN Memory Management.
I am following an example, but having issues in understanding the references.
var o = {
a: {
b:2
}
};
// 2 objects are created. One is referenced by the other as one of its property.
// The other is referenced by virtue of being assigned to the 'o' variable.
// Obviously, none can be garbage-collected
var o2 = o; // the 'o2' variable is the second thing that
// has a reference to the object
o = 1; // now, the object that was originally in 'o' has a unique reference
// embodied by the 'o2' variable
var oa = o2.a; // reference to 'a' property of the object.
// This object has now 2 references: one as a property,
// the other as the 'oa' variable
o2 = "yo"; // The object that was originally in 'o' has now zero
// references to it. It can be garbage-collected.
// However what was its 'a' property is still referenced by
// the 'oa' variable, so it cannot be free'd
oa = null; // what was the 'a' property of the object originally in o
// has zero references to it. It can be garbage collected.
I got confused by terms like this object, one is referenced by the other, 2 objects are created - for what? 'o' & 'a'?, that has a reference to the object - which object?
Can someone rephrase the comments above with the actual object names, please?
It may consider as a spoonfeeding question but let me know if it's not worth to ask this question. I'll delete it.