On Sun, Oct 24, 2010 at 11:09, Matthias Ernst <[email protected]> wrote: > On Sun, Oct 24, 2010 at 2:41 AM, Rasmus Andersson <[email protected]> wrote: >> On Sun, Oct 24, 2010 at 00:47, Marco Rogers <[email protected]> wrote: >>> Okay so does this mean that if you actually pass the handle back to js space >>> then it does become eligible for GC? What you set it to a property of an >>> object from js space? >> >> I don't think so. I built a test program which did just that. >> >> 1. Created a function in C-land, >> 2. Exposed it to a v8 script >> 3. Ran the script which called the function >> >> After hitting 1GB res. memory, none of the million instances had been >> released (yes, I yielded to v8 "IdleNotification" so GC could take >> place). >> >> I think you need to _create_ the instance in js-land for it to be >> subject to GC. If you define your own function type using >> FunctionTemplate and providing a custom initializer (usually a >> Handle<Value> New(const Arguments& args)), then when such an object is >> created in js-land, |args.Holder()| will contain an object which has >> been allocated by v8 and should be subject to GC. The problem seems to >> arise when _you_ create the "Holder" object. >> >>> I've been using the v8 API for a while now and I understand the basics (and >>> a bit more). I'm just trying to make sure I understand this particular >>> gotcha and how to avoid it. >> >> Same thing here. Would really appreciate some clarification from >> someone into v8 core dev. :) > > I ran into this, too, once: http://code.google.com/p/v8/issues/detail?id=733 > It is in fact documented that the lifetime of Function instances > created through the C++ api is scoped to the context - I think the > context pretty much holds a map from FunctionTemplate to Function > instances. > > So you only want to create a fixed number of instances per native - if > you need to bind an unlimited number of different "data" members, you > should bind them through JavaScript instead. I.e. instead of binding > "a", "b", "c", ... as "data" to a no-args foo(), expect it as a > parameter, create the native binding for foo once and do a "f = > function() { return foo(bound_arg); }". This f *will* be > garbage-collected when foo won't (until the context goes away). > > Note again this only applies to Functions. Other kinds of objects > created through the C++ api behave as expected. > > Matthias >
Thank you for the clarification! -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
