BOOLEAN_TO_JSVAL
DOUBLE_TO_JSVAL
INT_FITS_IN_JSVAL
INT_TO_JSVAL
JS::Add*Root
JS::AutoIdArray
JS::AutoSaveExceptionState
JS::AutoValueArray
JS::AutoVectorRooter
JS::BooleanValue
JS::Call
JS::CallArgs
JS::CloneFunctionObject
JS::Compile
JS::CompileFunction
JS::CompileOffThread
JS::CompileOptions
JS::Construct
JS::CreateError
JS::CurrentGlobalOrNull
JS::DeflateStringToUTF8Buffer
JS::DoubleNaNValue
JS::DoubleValue
JS::Evaluate
JS::FalseValue
JS::Float32Value
JS::GetDeflatedUTF8StringLength
JS::GetFirstArgumentAsTypeHint
JS::GetSelfHostedFunction
JS::Handle
JS::HandleValueArray
JS::IdentifyStandardInstance
JS::Int32Value
JS::IsCallable
JS::MutableHandle
JS::NewFunctionFromSpec
JS::NullHandleValue
JS::NullValue
JS::NumberValue
JS::ObjectOrNullValue
JS::ObjectValue
JS::OrdinaryToPrimitive
JS::PersistentRooted
JS::PropertySpecNameEqualsId
JS::PropertySpecNameIsSymbol
JS::PropertySpecNameToPermanentId
JS::ProtoKeyToId
JS::Remove*Root
JS::Rooted
JS::SetLargeAllocationFailureCallback
JS::SetOutOfMemoryCallback
JS::SourceBufferHolder
JS::StringValue
JS::SymbolValue
JS::ToBoolean
JS::ToInt32
JS::ToInt64
JS::ToNumber
JS::ToPrimitive
JS::ToString
JS::ToUint16
JS::ToUint32
JS::ToUint64
JS::TrueHandleValue
JS::TrueValue
JS::UndefinedHandleValue
JS::UndefinedValue
JS::Value
JSAutoByteString
JSAutoCompartment
JSBool
JSCheckAccessOp
JSClass
JSClass.call
JSClass.flags
JSConstDoubleSpec
JSConvertOp
JSDeletePropertyOp
JSEnumerateOp
JSErrorFormatString
JSErrorReport
JSExceptionState
JSExnType
JSExtendedClass
JSExtendedClass.outerObject
JSExtendedClass.wrappedObject
JSFUN_BOUND_METHOD
JSFUN_GLOBAL_PARENT
JSFastNative
JSFinalizeOp
JSFreeOp
JSFunction
JSFunctionSpec
JSGetObjectOps
JSHasInstanceOp
JSID_EMPTY
JSID_IS_EMPTY
JSID_IS_GCTHING
JSID_IS_INT
JSID_IS_STRING
JSID_IS_SYMBOL
JSID_IS_VOID
JSID_IS_ZERO
JSID_VOID
JSIdArray
JSIteratorOp
JSMarkOp
JSNative
JSNewEnumerateOp
JSNewResolveOp
JSObject
JSObjectOp
JSObjectOps.defaultValue
JSObjectOps.defineProperty
JSObjectOps.destroyObjectMap
JSObjectOps.dropProperty
JSObjectOps.enumerate
JSObjectOps.getAttributes
JSObjectOps.getProperty
JSObjectOps.getRequiredSlot
JSObjectOps.lookupProperty
JSObjectOps.newObjectMap
JSObjectOps.setProto
JSObjectPrincipalsFinder
JSPRINCIPALS_HOLD
JSPrincipals
JSPrincipalsTranscoder
JSProperty
JSPropertyDescriptor
JSPropertyOp
JSPropertySpec
JSProtoKey
JSReserveSlotsOp
JSResolveOp
JSRuntime
JSSecurityCallbacks.contentSecurityPolicyAllows
JSString
JSStringFinalizer
JSTraceOp
JSType
JSVAL_IS_BOOLEAN
JSVAL_IS_DOUBLE
JSVAL_IS_GCTHING
JSVAL_IS_INT
JSVAL_IS_NULL
JSVAL_IS_NUMBER
JSVAL_IS_OBJECT
JSVAL_IS_PRIMITIVE
JSVAL_IS_STRING
JSVAL_IS_VOID
JSVAL_LOCK
JSVAL_NULL
JSVAL_ONE
JSVAL_TO_BOOLEAN
JSVAL_TO_DOUBLE
JSVAL_TO_GCTHING
JSVAL_TO_INT
JSVAL_TO_OBJECT
JSVAL_TO_STRING
JSVAL_TRUE
JSVAL_UNLOCK
JSVAL_VOID
JSVAL_ZERO
JSVersion
JSXDRObjectOp
JS_ASSERT_STRING_IS_FLAT
JS_Add*Root
JS_AddArgumentFormatter
JS_AddExternalStringFinalizer
JS_AddFinalizeCallback
JS_AliasElement
JS_AliasProperty
JS_AlreadyHasOwnProperty
JS_BeginRequest
JS_BindCallable
JS_BufferIsCompilableUnit
JS_CStringsAreUTF8
JS_CallFunction
JS_CheckAccess
JS_CheckForInterrupt
JS_ClearContextThread
JS_ClearDateCaches
JS_ClearNewbornRoots
JS_ClearNonGlobalObject
JS_ClearPendingException
JS_ClearRegExpStatics
JS_ClearScope
JS_CloneFunctionObject
JS_CompareStrings
JS_CompileFileHandleForPrincipals
JS_CompileFileHandleForPrincipalsVersion
JS_CompileFunction
JS_CompileFunctionForPrincipals
JS_CompileScript
JS_CompileScriptForPrincipals
JS_CompileUCFunctionForPrincipalsVersion
JS_CompileUTF8File
JS_CompileUTF8FileHandle
JS_ConcatStrings
JS_ConstructObject
JS_ContextIterator
JS_ConvertArguments
JS_ConvertArgumentsVA
JS_ConvertValue
JS_DecompileFunction
JS_DecompileFunctionBody
JS_DecompileScript
JS_DecompileScriptObject
JS_DeepFreezeObject
JS_DefaultValue
JS_DefineConstDoubles
JS_DefineElement
JS_DefineFunction
JS_DefineFunctions
JS_DefineObject
JS_DefineOwnProperty
JS_DefineProperties
JS_DefineProperty
JS_DefinePropertyWithTinyId
JS_DeleteElement
JS_DeleteElement2
JS_DeleteProperty
JS_DeleteProperty2
JS_DestroyContext
JS_DestroyIdArray
JS_DestroyRuntime
JS_DestroyScript
JS_DoubleIsInt32
JS_DoubleToInt32
JS_DropExceptionState
JS_DumpHeap
JS_DumpNamedRoots
JS_EncodeCharacters
JS_EncodeString
JS_EncodeStringToBuffer
JS_EnterCompartment
JS_EnterCrossCompartmentCall
JS_EnterLocalRootScope
JS_Enumerate
JS_EnumerateDiagnosticMemoryRegions
JS_EnumerateResolvedStandardClasses
JS_EnumerateStandardClasses
JS_ErrorFromException
JS_EvaluateScript
JS_EvaluateScriptForPrincipals
JS_ExecuteRegExp
JS_ExecuteScript
JS_ExecuteScriptPart
JS_ExecuteScriptVersion
JS_FORGET_STRING_FLATNESS
JS_FS
JS_FileEscapedString
JS_Finish
JS_FlattenString
JS_FlushCaches
JS_ForgetLocalRoot
JS_ForwardGetPropertyTo
JS_FreezeObject
JS_GC
JS_GET_CLASS
JS_GetArrayLength
JS_GetArrayPrototype
JS_GetClass
JS_GetClassObject
JS_GetClassPrototype
JS_GetCompartmentPrivate
JS_GetConstructor
JS_GetContextPrivate
JS_GetContextThread
JS_GetDefaultFreeOp
JS_GetElement
JS_GetEmptyString
JS_GetEmptyStringValue
JS_GetErrorPrototype
JS_GetExternalStringClosure
JS_GetExternalStringFinalizer
JS_GetFlatStringChars
JS_GetFunctionArity
JS_GetFunctionCallback
JS_GetFunctionFlags
JS_GetFunctionId
JS_GetFunctionName
JS_GetFunctionObject
JS_GetFunctionPrototype
JS_GetFunctionScript
JS_GetGCParameter
JS_GetGlobalForCompartmentOrNull
JS_GetGlobalForObject
JS_GetGlobalForObject3
JS_GetGlobalForScopeChain
JS_GetGlobalObject
JS_GetImplementationVersion
JS_GetInstancePrivate
JS_GetInternedStringChars
JS_GetLatin1FlatStringChars
JS_GetLatin1InternedStringChars
JS_GetLatin1StringCharsAndLength
JS_GetLocaleCallbacks
JS_GetNaNValue
JS_GetObjectPrototype
JS_GetObjectRuntime
JS_GetOptions
JS_GetOwnPropertyDescriptor
JS_GetParent
JS_GetParentRuntime
JS_GetPendingException
JS_GetPositiveInfinityValue
JS_GetPrivate
JS_GetProperty
JS_GetPropertyAttributes
JS_GetPropertyAttrsGetterAndSetter
JS_GetPropertyDefault
JS_GetPropertyDescriptor
JS_GetPrototype
JS_GetRegExpFlags
JS_GetRegExpSource
JS_GetReservedSlot
JS_GetRuntime
JS_GetRuntimePrivate
JS_GetScopeChain
JS_GetSecurityCallbacks
JS_GetStringBytes
JS_GetStringCharAt
JS_GetStringChars
JS_GetStringCharsAndLength
JS_GetStringEncodingLength
JS_GetStringLength
JS_GetTwoByteExternalStringChars
JS_GetTypeName
JS_GetVersion
JS_HasArrayLength
JS_HasElement
JS_HasInstance
JS_HasOwnProperty
JS_HasProperty
JS_IdArrayGet
JS_IdArrayLength
JS_IdToProtoKey
JS_IdToValue
JS_Init
JS_InitCTypesClass
JS_InitClass
JS_InitStandardClasses
JS_InstanceOf
JS_InternJSString
JS_InternString
JS_IsArrayObject
JS_IsAssigning
JS_IsBuiltinEvalFunction
JS_IsBuiltinFunctionConstructor
JS_IsConstructing
JS_IsConstructing_PossiblyWithGivenThisObject
JS_IsConstructor
JS_IsExceptionPending
JS_IsExtensible
JS_IsExternalString
JS_IsGlobalObject
JS_IsIdentifier
JS_IsNative
JS_IsNativeFunction
JS_IsRunning
JS_IsStopIteration
JS_IterateCompartments
JS_LeaveCompartment
JS_LeaveCrossCompartmentCall
JS_LeaveLocalRootScope
JS_LeaveLocalRootScopeWithResult
JS_LinkConstructorAndPrototype
JS_Lock
JS_LockGCThing
JS_LookupElement
JS_LookupProperty
JS_LooselyEqual
JS_MakeStringImmutable
JS_MapGCRoots
JS_MaybeGC
JS_New
JS_NewArrayObject
JS_NewCompartmentAndGlobalObject
JS_NewContext
JS_NewDateObject
JS_NewDateObjectMsec
JS_NewDependentString
JS_NewDouble
JS_NewDoubleValue
JS_NewExternalString
JS_NewFunction
JS_NewGlobalObject
JS_NewNumberValue
JS_NewObject
JS_NewObjectForConstructor
JS_NewPlainObject
JS_NewPropertyIterator
JS_NewRegExpObject
JS_NewRuntime
JS_NewScriptObject
JS_NewStringCopyN
JS_NewStringCopyZ
JS_NewUCString
JS_NextProperty
JS_Now
JS_NumberValue
JS_ObjectIsDate
JS_ObjectIsFunction
JS_ObjectIsRegExp
JS_PSGS
JS_ParseJSON
JS_PopArguments
JS_PreventExtensions
JS_PropertyStub
JS_PushArguments
JS_PutEscapedString
JS_Remove*Root
JS_RemoveExternalStringFinalizer
JS_RemoveRootRT
JS_ReportError
JS_ReportErrorNumber
JS_ReportOutOfMemory
JS_ReportPendingException
JS_ResolveStandardClass
JS_RestoreExceptionState
JS_SET_TRACING_DETAILS
JS_SameValue
JS_SaveExceptionState
JS_SaveFrameChain
JS_ScheduleGC
JS_SealObject
JS_SetAllNonReservedSlotsToUndefined
JS_SetArrayLength
JS_SetBranchCallback
JS_SetCallReturnValue2
JS_SetCheckObjectAccessCallback
JS_SetCompartmentNameCallback
JS_SetContextCallback
JS_SetDefaultLocale
JS_SetDestroyCompartmentCallback
JS_SetElement
JS_SetErrorReporter
JS_SetExtraGCRoots
JS_SetFunctionCallback
JS_SetGCCallback
JS_SetGCParametersBasedOnAvailableMemory
JS_SetGCZeal
JS_SetGlobalObject
JS_SetICUMemoryFunctions
JS_SetInterruptCallback
JS_SetNativeStackQuota
JS_SetObjectPrincipalsFinder
JS_SetOperationCallback
JS_SetOptions
JS_SetParent
JS_SetPendingException
JS_SetPrincipalsTranscoder
JS_SetPrivate
JS_SetProperty
JS_SetPropertyAttributes
JS_SetPrototype
JS_SetRegExpInput
JS_SetScriptStackQuota
JS_SetThreadStackLimit
JS_SetVersion
JS_SetVersionForCompartment
JS_ShutDown
JS_StrictlyEqual
JS_StringEqualsAscii
JS_StringHasBeenInterned
JS_StringHasLatin1Chars
JS_StringIsFlat
JS_StringToVersion
JS_SuspendRequest
JS_THREADSAFE
JS_ThrowStopIteration
JS_ToggleOptions
JS_TracerInit
JS_TypeOfValue
JS_Unlock
JS_ValueToBoolean
JS_ValueToECMAInt32
JS_ValueToFunction
JS_ValueToId
JS_ValueToInt32
JS_ValueToNumber
JS_ValueToObject
JS_ValueToSource
JS_ValueToString
JS_VersionToString
JS_YieldRequest
JS_freeop
JS_malloc
JS_updateMallocCounter
OBJECT_TO_JSVAL
PRIVATE_TO_JSVAL
Property attributes
STRING_TO_JSVAL
Stored value
jschar
jsdouble
jsid
jsint
This guide explains the basics of interacting with SpiderMonkey's GC as a SpiderMonkey API user. Since SpiderMonkey has a moving GC, it is very important that it knows about each and every pointer to a GC thing in the system. SpiderMonkey's rooting API tries to make this task as simple as possible.
"GC thing" is the term used to refer to memory allocated and managed by the SpiderMonkey garbage collector. The main types of GC thing pointer are:
Note that JS::Value and jsid can contain pointers internally even though they are not a normal pointer type, hence their inclusion in this list.
If you use these types directly, or create classes, structs or arrays that contain them, you must follow the rules set out in this guide. If you do not your program will not work correctly - if it works at all.
All GC thing pointers stored on the stack (i.e., local variables and parameters to functions) must use the JS::Rooted<T>
class. This is a template class where the template parameter is the type of the GC thing it contains. From the user perspective, a JS::Rooted<T>
instance behaves exactly as if it were the underlying pointer.
JS::Rooted
must be constructed with a JSContext*
, and optionally an initial value.
There are typedefs available for the main types. Within SpiderMonkey, it is suggested that these are used in preference to the template class (Gecko uses the template versions):
Template class | Typedef |
---|---|
JS::Rooted<JS::Value> | JS::RootedValue |
JS::Rooted<JSObject*> | JS::RootedObject |
JS::Rooted<JSString*> | JS::RootedString |
JS::Rooted<JSScript*> | JS::RootedScript |
JS::Rooted<jsid> | JS::RootedId |
For example, instead of this:
JSObject* localObj = JS_GetObjectOfSomeSort(cx);
You would write this:
JS::RootedObject localObj(cx, JS_GetObjectOfSomeSort(cx));
SpiderMonkey makes it easy to remember to use JS::Rooted<T>
types instead of a raw pointer because all of the API methods that may GC take a JS::Handle<T>
, as described below, and JS::Rooted<T>
autoconverts to JS::Handle<T>
but a bare pointer does not.
All GC thing pointers that are parameters to a function must be wrapped in JS::Handle<T>
. A JS::Handle<T>
is a reference to a JS::Rooted<T>
, and is created implicitly by referencing a JS::Rooted<T>
: It is not valid to create a JS::Handle<T>
manually (the whole point of a Handle is that it only reference pointers that the GC knows about so it can update them when they move). Like JS::Rooted<T>
, a JS::Handle<T>
can be used as if it were the underlying pointer.
Since only a JS::Rooted<T>
will cast to a JS::Handle<T>
, the compiler will enforce correct rooting of any parameters passed to a function that may trigger GC. JS::Handle<T>
exists because creating and destroying a JS::Rooted<T>
is not free (though it only costs a few cycles). Thus, it makes more sense to only root the GC thing once and reuse it through an indirect reference. Like a reference, a JS::Handle
is immutable: it can only ever refer to the JS::Rooted<T>
that it was created for.
Similarly to JS::Rooted<T>
, there are typedefs available for the main types:
Template class | Typedef |
---|---|
JS::Handle<JS::Value> | JS::HandleValue |
JS::Handle<JSObject*> | JS::HandleObject |
JS::Handle<JSString*> | JS::HandleString |
JS::Handle<JSScript*> | JS::HandleScript |
JS::Handle<jsid> | JS::HandleId |
You should use JS::Handle<T>
for all function parameters taking GC thing pointers (except out-parameters, which are described below). For example, instead of:
JSObject * someFunction(JSContext *cx, JSObject* obj) { // ... }
You should write:
JSObject * someFunction(JSContext *cx, JS::HandleObject obj) { // ... }
All GC thing pointers that are used as out-parameters must be wrapped in a JS::MutableHandle<T>
. A JS::MutableHandle<T>
is a reference to a JS::Rooted<T>
that, unlike a normal handle, may modify the underlying JS::Rooted<T>
. All JS::MutableHandle<T>
s are created through an explicit "&" - address of operator - on a JS::Rooted<T>
instance. JS::MutableHandle<T>
is exactly like a JS::Handle<T>
except that it adds a .set(T &t)
method and must be created from a JS::Rooted<T>
explicitly.
There are typedefs for JS::MutableHandle<T>
, the same as for the other templates:
Template class | Typedef |
---|---|
JS::MutableHandle<JS::Value> | JS::MutableHandleValue |
JS::MutableHandle<JSObject*> | JS::MutableHandleObject |
JS::MutableHandle<JSString*> | JS::MutableHandleString |
JS::MutableHandle<JSScript*> | JS::MutableHandleScript |
JS::MutableHandle<jsid> | JS::MutableHandleId |
JS::MutableHandle<T>
should be used for all out-parameters, for example instead of:
bool maybeGetValue(JSContext *cx, JS::Value* valueOut) { // ... if (!wasError) *valueOut = resultValue; return wasError; } void otherFunction(JSContext *cx) { JS::Value value; bool success = maybeGetValue(cx, &value); // ... }
You should write:
bool maybeGetValue(JSContext *cx, JS::MutableHandleValue valueOut) { // ... if (!wasError) valueOut.set(resultValue); return wasError; } void otherFunction(JSContext *cx) { JS::RootedValue value(cx); bool success = maybeGetValue(cx, &value); // ... }
It's ok to return raw pointers! These do not need to be wrapped in any of rooting classes, but they should be immediately used to initialize a JS::Rooted<T>
if there is any code that could GC before the end of the containing function; a raw pointer must never be stored on the stack during a GC.
One rare but especially tricky case to watch out for is where an RAII destructor could GC in a function that is returning a bare pointer. Consider:
JSObject* someFunction(JSContext* cx) { JS::Rooted<JSObject*> obj(cx, foo()); EventLogger logger(cx); ...code... return obj; }
Say that ~EventLogger constructs some sort of object in its destructor, which could trigger a GC. What will happen is that the return statement will pull the bare JSObject* out of the rooted obj variable and either put it in the stack or store it in the return value register. Then ~EventLogger will fire and trigger a GC, invalidating that unrooted stack/register pointer. This scenario is rare but very difficult to notice manually, and will probably be caught by the static rooting hazard analysis. There are two different approaches to resolving this; use whichever better fits your situation:
void someFunction(JSContext* cx, JS::MutableHandleObject obj) { EventLogger(cx); ...code... obj.set(foo()); }
(note that the above should probably check the return value and propagate an error on null), or:
JSObject* someFunction(JSContext* cx) { JS::Rooted<JSObject*> obj(cx, foo()); { // Make a scope to force the destructor to run before obj is unwrapped. EventLogger(cx); ...code... } return obj; }
GC thing pointers that appear as part of a stack-allocated aggregates (array, structure, class, union) should use JS::Rooted<T>
when possible.
There are some situations when using JS::Rooted<T>
is not possible, or is undesirable for performance reasons. To cover these cases, there are various AutoRooter
classes that can be used.
Here are the main AutoRooters defined:
Type | AutoRooter class |
---|---|
JS::Value[] | AutoArrayRooter |
js::Vector<JS::Value> | AutoValueVector |
js::Vector<jsid> | AutoIdVector |
js::Vector<JSObject*> | AutoObjectVector |
js::Vector<JSScript*> | AutoScriptVector |
If your case is not covered by one of these, it is possible to write your own by deriving from JS::CustomAutoRooter
and overriding the virtual trace()
method. The implementation should trace all the GC things contained in the object by calling JS::TraceEdge
.
GC thing pointers on the heap must be wrapped in a JS::Heap<T>
. The only exception to this is if they are added as roots with the JS::PersistentRooted class, but don't do this unless it's really necessary. JS::Heap<T>
pointers must also continue to be traced in the normal way, which is covered below.
JS::Heap<T>
doesn't require a JSContext*
, and can be constructed with or without an initial value parameter. Like the other template classes, it functions as if it were the GC thing pointer itself.
One consequence of having different rooting requirements for heap and stack data is that a single structure containing GC thing pointers cannot be used on both the stack and the heap. In this case, separate structures must be created for the stack and the heap.
There are currently no convenience typedefs for JS::Heap<T>
.
For example, instead of this:
struct HeapStruct { JSObject* mSomeObject; JS::Value mSomeValue; };
You should write:
struct HeapStruct { JS::Heap<JSObject*> mSomeObject; JS::Heap<JS::Value> mSomeValue; };
All GC pointers stored on the heap must be traced. For regular js::NativeObject
s, this is normally done by storing them in slots, which are automatically traced by the GC.
When defining a JSObject subclass that contains Heap<T>
fields, set the trace hook to invoke a function that traces those fields.
For a regular struct
or class
, tracing must be triggered manually. The usual way is to define a void trace(JSTracer* trc, const char* name)
method on the class -- which is already enough be able to create a JS::Rooted<YourStruct>
on the stack -- and then arrange for it to be called during tracing. If a pointer to your structure is stored in the private field of a JSObject, the usual way would be to define a trace hook on the JSObject (see above) that casts the private pointer to your structure and invokes trace()
on it:
class MyObject : public JSObject { { ... static void trace(JSTracer* trc, JSObject* obj) { MyClass* mine = static_cast<MyClass*>(obj->getPrivate()); mine->trace(trc, "MyClass private field"); } } class MyClass { Heap<JSString*> str; public: void trace(JSTracer* trc, const char* name) { JS::TraceEdge(trc, &str, "my string"); } }
If a pointer to your structure is stored in some other structure, then its trace()
method should invoke yours:
struct MyOwningStruct { MyClass* mything; void trace(JSTracer* trc, const char* name) { if (mything) mything->trace(trc, "my thing"); } }
If the toplevel structure is not stored in a JSObject
, then how it gets traced depends on why it should be alive. The simplest approach is to use JS::PersistentRooted
(usable on anything with a trace method with the appropriate signature):
JS::PersistentRooted<MyOwningStruct> immortalStruct;
But note that JS::PersistentRooted
in a struct or class is a rather dangerous thing to use -- it will keep a GC thing alive, and most GC things end up keeping their global alive, so if your class/struct is reachable in any way from that global, then nothing will ever be cleaned up by the GC.
JS::Rooted<T>
typedefs for local variables on the stack.JS::Handle<T>
typedefs for function parameters.JS::MutableHandle<T>
typedefs for function out-parameters.JS::Rooted<T>
to get a JS::Handle<T>
.JS::Rooted<T>
to get a JS::MutableHandle<T>
.JS::Rooted<T>
fields when possible for aggregates, otherwise use an AutoRooter.JS::Heap<T>
members for heap data. Note: Heap<T>
are not "rooted": they must be traced!JS::Rooted<T>
, JS::Handle<T>
or JS::MutableHandle<T>
on the heap.JS::Rooted<T>
for function parameters.JS::PersistentRooted<T>
for things that are alive until the process exits (or until you manually delete the PersistentRooted for a reason not based on GC finalization.)