Garbage-Collected Types
JavaScriptCore has an automatic garbage-collector that scans the stack to see if a JavaScript value has any active references. When no references are found, the value will be collected (freed).
JSValueRef and JSObjectRef Types
Both JSValueRef and JSObjectRef are garbage-collected types-- if they go out of scope on the stack and are not stored in a global JavaScript object, they will be marked for collection.
Storing Values on the Heap
If you store JSValueRef or JSObjectRef on a static global or on the heap, the GC may inadvertently free these objects potentially causing memory corruption / crashes. To prevent this you should use JSValueProtect() and JSValueUnprotect() to keep them alive.
Updated 5 months ago
What’s Next
