I am currently rethinking the object dispose handling of the qooxdoo JavaScript framework.
Have a look at the following diagram (A is currently in scope):
diagram http://yuml.me/51747906.jpg
Let’s say we want to delete B. Generally, we cut all reference between all objects. This means we cut connection 1 to 5 in the example. Is this really necessary?
As far as I have read here, browsers use the mark-and-sweep algorithm. In that case, we just need to cut reference 1 (connection to the scope) and 5 (connection to the DOM) which could be much faster.
But can I be sure that all browsers use the mark-and-sweep algorithm or something similar?
For any decent garbage collector (not only mark-and-sweep), cutting connection 1 would be enough to release B (and C and D and the window). Allocation based on reference counting would fail to release B and D due to their cyclic references (B references D and D references B) but reference counting is not really garbage collection.
I think it is safe to assume that all browsers use a decent garbage collector (well, with browsers, nothing is ever really safe, but a JavaScript implementation not using a proper garbage collector is improbable nonetheless).