I'm writing an addon for nodejs with v8.  The library is libxmljs and
it provides an implementation of a DOM using the libxml2 library.  I
would appreciate some guidance on a problem I need to solve.

The short description of my problem is I've got C++ objects
referencing libxml structs.  The structs themselves are organized into
the DOM tree by libxml.  So the C++ objects don't reference each other
directly.  I'm using persistent handles point to the C++ objects to
keep them from being collected.  But what I need is a to keep the
Persistent handles from being weak.  Right now they're always weak and
they get collected during idle times when the GC runs.  I have two
likely strategies for this.

1. Reference counting.  I can add reference updates in my api that inc/
dec the count when a node is added to or removed from the DOM tree.
This would work and is my second option.  It's not at the top of my
list simply because I can imagine #2 being a little easier to
maintain.

2. References to all persistent handles to a DOM node are non-weak and
kept in a persistence list.  They are added when the node is added to
the DOM  tree and they are kept around for the life of the document.
When the document is freed, the list is released and the handles are
all made weak and eligible for collection.  This seems sensible and
you only have to manage the list in 2 places.  On node creation and on
document destruction.

I was pointed to the api method v8::V8::AddObjectGroup to try and
accomplish this.  But I can't find very much info on how to use it
effectively.  Also, even if I could populate it with my objects, the
api description says it is released after every GC.  Is there a way to
prevent that?  I would like it to stick around until explicitly
released?

I would appreciate input on either of these methods.  Thanks.

:Marco

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to