JS::SetOutOfMemoryCallback

This article covers features introduced in SpiderMonkey 31

Specify a new callback function for Out of Memory error.

Syntax

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

Callback syntax

typedef void
(* OutOfMemoryCallback)(JSContext *cx, void *data);
Name Type Description
data void * data parameter passed to JS::SetOutOfMemoryCallback. Added in SpiderMonkey 38

Description

Unlike the error reporter, which is only called if the exception for an OOM bubbles up and is not caught, the JS::OutOfMemoryCallback is called immediately at the OOM site to allow the embedding to capture the current state of heap allocation before anything is freed. If the large-allocation-failure callback is called at all (not all allocation sites call the large-allocation-failure callback on failure), it is called before the out-of-memory callback; the out-of-memory callback is only called if the allocation still fails after the large-allocation-failure callback has returned.

JS::SetOutOfMemoryCallback sets a callback function for it.

See Also

Document Tags and Contributors

 Contributors to this page: kscarfone, arai
 Last updated by: kscarfone,