My analysis leads me to a similar conclusion. Reference counting is  
out and there is no need for it. This is my hypothesis:

If things are being freed unintentionally, then there are not enough  
ruby to ruby cross-references to maintain integrity during mark and  
sweep. A single ruby object holding on to an xmlNode should inhibit  
collection of an entire tree. Individual ruby xml nodes can be  
reaped, but there should be no xmlFree done by anything but the  
document level object. As for an xmlNode that is not associated with  
a document, it must call xmlFree (the xmlNode already indicates if it  
is associated with a document) if it has no parent. Which effectively  
translates into the same document semantics.

One operational change should be once an xmlNode is associated with a  
document it cannot be associated with another one (at least using the  
implicit copy mechanism provided in ruby_xml_node_child_set). The  
ruby xmlNode becomes changed and reflects its association with the  
document. However, using xmlCopyNode, it is possible to get a copy of  
the node without an association to the document and also libxml2  
handles propagation of namespaces. This new copy preserves the  
document based free condition above, and also makes it easy to put it  
into another document. Not sure if this should be automatic (thinking  
not) or an overload of .dup.

This should establish a bright line between libxml2 and ruby for  
managing memory.

This is from only a few hours looking at the docs and source code for  
libxml2, the python interface and the ruby interface.  If these seem  
to ignore some known pitfall, please let me know. If not, this should  
fix this scope of the memory problem.

I intend to do this within a week. Post your warnings or wish me luck.

Dan


On Aug 23, 2007, at 14:25, Sean Chittenden wrote:

> Having spent a great deal of time with this, I'm now of the following
> opinion of this library: when initially writing this module, I
> exposed too much of libxml to Ruby and the memory models and object/
> tree dependencies and interactions between memory and objects is...
> problematic and should be reviewed.  $0.02.  -sc
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to