Subj : finilize & construct: call disbalance To : netscape.public.mozilla.jseng From : anton muhin Date : Thu Jul 08 2004 05:18 pm Hello, everybody! First of all, thank you for SpiderMonkey product --- it's really good. The problem: I have a problem with misbalanced calls of constructor and finilizers. Details: I extend JavaScript with a class that in construction allocates some private data and sets them to the object. In the finilizer I free these data. The JavaScript session is really simple: js> var c = new MyClass() js> quit() With the session my constructor (in C) is called once. However, the finilizer (in C also) is called three times and it's only the last time when it gets called with the object created in the constructor. Is it normal or I do something stupid? Abridged versions of the constructor and finilizer (all the checks removed): JSBool my_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSObject * o = JS_NewObject(cx, &kls, NULL, NULL); void * data = malloc(SIZE); JS_SetPrivate(cx, o, data); *rval = OBJECT_TO_JSVAL(o); return JS_TRUE; } void my_finalize(JSContext *cx, JSObject *obj) { void * data = JS_GetPrivate(cx, obj); free(data); } thank you for your time, anton. .