Re: How do I trace objects on the heap with JS 59

Boris Zbarsky <[email protected]> Thu, 9 Aug 2018 11:12:25 -0400
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On 8/9/18 4:40 AM, Miles wrote:
> Alternatively it looks like I could use the JS::PersistentRooted class to do what I want but it specifically says not to do this unless it's really necessary. Why is that then? Is it some sort of performance issue?

Well, if nothing else it makes it easy to leak.  Say you have two C/C++ 
data structures X and Y.  X holds on to a PersistentRooted for object A, 
object A keeps Y alive, Y holds a PersistentRooted for object B, B keeps 
X alive.  Now you have a leak.

As far as how to trace things goes, it depends on what owns the heap 
data structures that are pointing to the JS objects.  If they are owned 
(possibly indirectly) by some SpiderMonkey object, its trace class hook 
should do the tracing.  If they just exist independently, then 
JS_AddExtraGCRootsTracer might be the right thing?

-Boris