Hi,

At Wed, 16 Jul 2008 07:14:52 +0900,
Charlie Savage wrote in [ruby-core:17791]:
> > After looking this over, I tend to agree with Nobu's later comment that
> > reference counting may be useful here.  XML::Node::Set object might:
> > 
> >  1. increment a reference count in the parent XML document object, and 
> >  2. have each document object include a flag that indicated that Ruby's GC
> > had
> >      attempted to free it while its reference count was non-zero.
> > 
> > In this case:
> >  3. The XML::Node::Set's dfree would decriment the document's refcount, and
> >  4. only if it reached zero and the document object's dfree had already been
> > called,
> >      would it would also free the document object.

Brent, thank you for the clear explanation.

> What happens though when Document#free gets called first?  Then there is 
> no way to avoid a segmentation fault, except not releasing the Node's Co 
> object (which I guess is ok since the process is shutting down, but 
> hardly good programming form).

The order of Document and Node::Set has no sense.

  3. The XML::Node::Set's and the XML::Document's dfree would
     decriment the document's refcount, and

  4. only if it reached zero, regardless which dfree, it would
     also free the document object.

> That should work, but its seems like this should be general issue with a 
> general solution (ala mark/sweep).

Yes, so refcount would be helpful.

-- 
Nobu Nakada