Thanks Ben, that was enough of a nudge in the right direction that I was 
able to figure things out I think.  If you have time, could you possibly 
review https://github.com/mattness/addonSample/commit/8c775e96 to confirm?

Thank you very much for your help.  I appreciate it.

Matt

On Tuesday, March 20, 2012 11:22:58 PM UTC-4, Ben Noordhuis wrote:
>
> On Wed, Mar 21, 2012 at 03:21, Matt Gollob wrote:
> > Hello everyone -
> >
> > I'd like some feedback with regard to a sample addon I've put together 
> for
> > node to demonstrate exposing a C++ library to javascript.  In particular,
> > I'm struggling with how to properly manage memory allocated from C++ when
> > its lifetime is coupled to the lifetime of a javascript handle.
> >
> > The repository is on Github at https://github.com/mattness/addonSample.
> >  Specifically, I'm looking for help with the following:
> >
> > https://github.com/mattness/addonSample/blob/master/src/binding.cc#L53
> > (Freeing a C++ heap-allocated object when JS object it's tied to gets 
> GC'd)
> > 
> https://github.com/mattness/addonSample/blob/master/src/native_object_wrapper.cc#L23
> >  (Whether or not a v8::ObjectTemplate can be defined once and reused)
> > 
> https://github.com/mattness/addonSample/blob/master/src/native_object_wrapper.cc#L38
> >  (The appropriate use of Persistent handles, and when/where to call 
> Dispose
> > and Clear)
> >
> > Any other feedback is welcome as well.  Thanks so much for your time!
> >
> > Matt
>
> Take a look at how node::ObjectWrap does it. Basically, you stuff your
> object in a Persistent handle and call MakeWeak on it. It's your
> WeakReferenceCallback that cleans up the C++ resources.
>
> We also call MarkIndependent but that's an optimization: marking a
> handle independent means the garbage collector can make some
> assumptions that (hopefully) speed up sweeps.
>
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to