In message <[EMAIL PROTECTED]>
          Marc Munro <[EMAIL PROTECTED]> wrote:

> On Thu, 2007-23-08 at 11:13 -0600, Charlie Savage wrote:
> > Ah - interesting.  A hybrid approach is extremely difficult because it
> > means you have to keep track of the ruby to libxml object mapping.  For
> > example, say you have some ruby code that create a libxml node.  That
> > ruby object would then implement a free method that frees the libxml
> > node.  But let's say you end up with a 2nd ruby object pointing to the
> > same libxml object (which is really easy to do) - now you have a problem.
> 
> The current implementation uses a reference counting scheme within the
> xmlNode elements returned from libxml.  It seems to me that it *should*
> be possible for this to work.

Reference counting can't work, because the references held by
other libxml objects are not counted, and libxml does not respect
them so will free things that still have a non-zero reference
count.

As I recall my patch works round this by setting a callback in
libxml so that it finds out when a libxml object is being
destroyed and can duplicate it if it is still being referenced
by ruby objects.

> The problems that I have discovered stem from libxml freeing entire
> document trees while there are still ruby objects referencing the nodes.
> When those ruby objects are subsequently garbage-collected, the xmlNodes
> in those objects have already been freed and sadness ensues.  But I
> think the current mechanism is so close to working that it does not
> warrant a complete rewrite.

That is precisely the problem.

> As far as I can see, all trees should simply be walked prior to calling
> XMLFree to check for nodes referenced from ruby.  Any such nodes should
> be removed from the tree, as they will be freed later when their
> referencing objects are garbage-collected.  This probably also applies
> to attributes but that hasn't bitten me yet.

I was trying to avoid having to do anything that expensive I think
although I certainly considered it.

Tom

-- 
Tom Hughes ([EMAIL PROTECTED])
http://www.compton.nu/
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to