Monday 12 November 2001
Gone back to working on the my DOM implementation. I'd realised that the reference counting scheme I was using was completely wrong, and the whole thing would be tied up in a circular reference. You can't keep a reference count on each node in the tree, but
on the tree as a whole
. Given any node, you can always get back to the document node and navigate around, so you have to hold the whole tree until it's all finished with. Once the last reference to any part of the tree is released, then you can destroy the whole tree, but not before.
I've set thing up now so that each node forwards the reference count to its owning document. Once the document is destroyed each node destroys its children. The only thing you have to keep track off then are nodes which have been removed from the tree, or which have been created but not yet added (i.e. those obtained via cloneNode or create*).