Subj : Re: System resource wrapping To : netscape.public.mozilla.jseng From : Ludovic Delabre Date : Thu Feb 10 2005 06:46 pm Hello! Why do you think the GC would destroy object "like that" ? I assume that object are always kept alive as long as they are referenced - that's the point of a GC, no ? Ludovic. Matthew Mondor wrote: > Hi, > > I have created a custom class with SpiderMonkey which needs to wrap a > filedescriptor internally. When the object is constructed, it allocates > necessary system resources, including opening a file and storing the > filedescriptor. This data is stored in the private member of the > object, and retreived by other related methods of that class. This > seems to be working well so far, however I have been wondering: > > Since these objects hold a filedescriptor to an open file, and that > there is a close() method which the caller uses at will to free that > resource, is it possible for GC operation in some circumstances to call > the finalizer function of that object inadvertantly? If so, I can close > all resources in the finalizer, but wouldn't the user like magically > loose it's object at times? > > Since this is sortof a user script controlled resource, unlike most > temporary objects which can be discarded implicitely, these need to be > discarded explicitely in general. Does this mean that I should use > something like JS_AddRoot() to prevent any kind of inadvertent GC > operation on them? I.E. is this a proper candidate to be added to the > root. > > Thanks, > Matt .