I'm not sure why this seems tough.  If we have a reference to a leaf
when we want to garbage collect the rest of the tree, I am suggesting
removing that leaf from the tree prior to freeing it.

You don't view the tree as atomic?  Seems to me it is.

When you add the Ruby objects to a tree, the Ruby objects can give up ownership (that's simple, set the free method to nil).

That would be quite a change to the API.  As it is I can do either of
these things and both seem reasonable:

doc = XML::Document.new root = XML::node.new('node')
  doc.root = root
  root['wibble'] = 'wibble'

or

  doc = XML::Document.new
  root = XML::node.new('node')
  root['wibble'] = 'wibble'
  doc.root = root

I suspect my app does both, so I wouldn't like to see that change.

I don't think your Ruby code would change at all. Under the covers, the bindings would see that you are adding root to to doc, and so the Ruby object pointing to root would give up ownership.

You'd then setup a mark function for each node. The mark function would alert the Ruby garbage collector that the doc Ruby object is still in use (because you have Ruby objects pointing to child nodes).

When eventually all Ruby objects pointing to nodes are no longer in use, Ruby's garbage collector will collect the doc object which in turn will free the libxml tree.

Seems nice and simple to me, avoids all reference counting, and leverages Ruby's mark-and-sweep garbage collector.

So am I missing something?

Charlie

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to