Can somebody explain in detail how Javascript engines deal with circular references ? Is there a big difference between browsers or even node.js ?
What I'm talking about is an explicit back-/next reference within objects. For instance:
var objA = {
prop: "foo",
next: null
};
var objB = {
prop: "foo",
prev: null
};
objA.next = objB;
objB.prev = objA;
There we go. If we do a console.log( objA )
we can see that we created an infinite chain.
The big question is, is this bad ? Does it create memory leaks when not explicitly cleaned?
So do we have to
objA.next = null;
objB.prev = null;
or will the garbage collectors take care of us on constellations like this?
See Question&Answers more detail:os