Subj : xpconnect object lifetime using nsIXPCScriptable To : netscape.public.mozilla.jseng From : Ulrich von Zadow Date : Wed Sep 17 2003 11:05 pm Hi, we have xpcom components here that inherit from nsIXPCScriptable and we've run into a situation where we can't seem to get rid of a memory leak. Basically, we're returning an xpcom component from GetProperty: NS_IMETHODIMP acXPCDynamicProperties::GetProperty (nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj, jsval id, jsval * vp, PRBool *_retval) { [...] scope= ??? nsISupports * native = ... { nsCOMPtr holder; nsresult rv = getXPConnect()->WrapNative(cx, scope, native, aIID, getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); JSObject* obj = nsnull; rv = holder->GetJSObject(&obj); NS_ENSURE_SUCCESS(rv, rv); *vp = OBJECT_TO_JSVAL(obj); } [...] } On the native side, we seem to be reference counting correctly. In the WrapNative() call, the reference count goes up by two - I have no way of verifying that that is as intended. We're also unsure about what to pass as scope. Since we're returning a value, the reference to that value should be gone when the stack frame is discarded. How is this accomplished? Is WrapNative the correct function to call at all if we want the object to be rooted locally? Thanks for any help, Uli .