This is an archived page. It's not actively maintained.


This article covers features introduced in SpiderMonkey 31

Specify a new callback function for large memory allocation failure.


JS::SetLargeAllocationFailureCallback(JSRuntime *rt,
                                      JS::LargeAllocationFailureCallback afc,
                                      void *data);
Name Type Description
rt JSRuntime * The JSRuntime for which to set the GC callback.
cb JS::LargeAllocationFailureCallback Pointer to the new callback function to use.
data void * data parameter which will be passed to JS::LargeAllocationFailureCallback. Added in SpiderMonkey 38

Callback syntax

typedef void
(* JS::LargeAllocationFailureCallback)(void *data);
Name Type Description
data void * data parameter passed to JS::SetLargeAllocationFailureCallback. Added in SpiderMonkey 38


If a large allocation fails when calling pod_{calloc,realloc}CanGC, the JS engine may call the large-allocation- failure callback, if set, to allow the embedding to flush caches, possibly perform shrinking GCs, etc. to make some room. The allocation will then be retried (and may still fail.)

JS::SetLargeAllocationFailureCallback sets a callback function for it.

See Also