JS_ReportOutOfMemory

Reports a memory allocation error.

Syntax

void
JS_ReportOutOfMemory(JSContext *cx);
void
JS_ReportAllocationOverflow(JSContext *cx); // Added in SpiderMonkey 1.8
Name Type Description
cx JSContext * The context in which to report the error.

Description

Call JS_ReportOutOfMemory to report that an operation failed because the system is out of memory. When the JavaScript engine tries to allocate memory and allocation fails, it reports an error as though by calling this function.

Call JS_ReportAllocationOverflow if an operation fails because it tries to use more memory (or more of some other resource) than the application is designed to handle. When a script tries to grow an array beyond 230-1 elements, for example, or concatenate strings such that the result is more than 229-1 characters long, the JavaScript engine reports an error as though by calling this function.

The main difference between these two functions is that JS_ReportOutOfMemory does not cause a JavaScript exception to be thrown. The error therefore cannot be caught by try…catch statements in scripts. JS_ReportAllocationOverflow throws an InternalError which scripts can catch.

See JS_ReportError and JS_SetErrorReporter for more information about error handling in the JSAPI.

See Also

Document Tags and Contributors

 Contributors to this page: arai, fscholz, Jorend, Dria, MMondor
 Last updated by: arai,