[XML-SIG] Re: FREE DOM

Andrew Kuchling akuchlin@cnri.reston.va.us
Tue, 8 Sep 1998 10:18:56 -0400 (EDT)


John Totten writes (in a private message):
>Anyone working on a Python version of SAXDOM/FREEDOM?
>					John Totten

	[Cc'ed to xml-sig@python.org, because the answer is of interest]
	
	I spent some of this weekend working on the PyDOM code, trying
to bring it into compliance with the most recent DOM spec.  Nothing
releasable yet, though, though it hopefully won't take much longer.
DOM's moving through the W3C's process faster than I expected,
possibly becoming a Recommendation in September.  Therefore I think a
DOM implementation should be part of 1.0, instead of being postponed
until after 1.0.

	Garbage collection is going to be a problem, though.  DOM
nodes allow retrieving both the parent node, and the children.  The
obvious implementation is to have .parent and .children attributes,
but those create cycles, which will lead to uncollected garbage.  

	One solution is to require calling a .destroy() (or
similarly-named) method when you're done with a node.  The method
would then do something like:

	def destroy(self):
	    del self.parent
            for i in self.children:
	        i.destroy()
	    del self.children

This is simple to implement, but it means that you have to remember to
call .destroy().  Does anyone see a representation that would avoid
the necessity of doing this?  I was thinking of just having .children
in each node, and then there would be a global dictionary that mapped
nodes to their parent objects.  Because it's global, it wouldn't
participate in any cycles, but cleaning it up is also a pain.  

	Anyone have a suggestion?  (Other than continually visiting
Guido and whining for non-refcounting GC?)

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
It was a wasted life, but God forbid that one should be hard upon it, or upon
anything in this world that is not deliberately and coldly wrong . . .
    -- Charles Dickens, in a letter to his friend John Forster.