This article covers features introduced in SpiderMonkey 31
Specify a new callback function for large memory allocation failure.
Syntax
void
JS::SetLargeAllocationFailureCallback(JSRuntime *rt,
                                      JS::LargeAllocationFailureCallback afc,
                                      void *data);
| Name | Type | Description | 
|---|---|---|
| rt | JSRuntime * | The JSRuntimefor which to set the GC callback. | 
| cb | JS::LargeAllocationFailureCallback | Pointer to the new callback function to use. | 
| data | void * | dataparameter which will be passed toJS::LargeAllocationFailureCallback. Added in SpiderMonkey 38 | 
Callback syntax
typedef void (* JS::LargeAllocationFailureCallback)(void *data);
| Name | Type | Description | 
|---|---|---|
| data | void * | dataparameter passed toJS::SetLargeAllocationFailureCallback. Added in SpiderMonkey 38 | 
Description
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.