From: Raymond S. <dst...@or...> - 2001-02-21 16:02:42
|
JavaScript-1.5 Reference JS_GC Function Summary Performs garbage collection in the JS memory pool. Syntax void JS_GC(JSContext *cx); Description JS_GC performs garbage collection, if necessary, of JS objects, doubles, and strings that are no longer needed by a script executing in a specified JSContext, cx. Garbage collection frees space in the memory pool so that it can be reused by the JS engine. When you use JS_malloc and JS_realloc to allocate memory for executable script contexts, these routines automatically invoke the garbage collection routine. When your scripts create many objects, you may want to call JS_GC directly in your code, particularly when request ends or a script terminates. To run garbage collection only when a certain amount of memory has been allocated, you can call JS_MaybeGC instead of JS_GC. JS_malloc Function Summary Allocates a region of memory for use. Syntax void * JS_malloc(JSContext *cx, size_t nbytes); Name Type Description cx JSContext * Pointer to a JS context from which to derive runtime information. nbytes size_t Amount of space, in bytes, to allocate. Description JS_malloc allocates a region of memory nbytes in size. If the allocation is successful, JS_malloc returns a pointer to the beginning of the region. If the memory cannot be allocated, JS_malloc passes cx to JS_ReportOutOfMemory to report the error, and returns a null pointer. As with a standard C call to malloc, the region of memory allocated by this call is uninitialized and should be assumed to contain meaningless information. Notes Currently JS_malloc is a wrapper on the standard C malloc call. Do not make assumptions based on this underlying reliance. Future versions of JS_malloc may be implemented in a different manner. JS_realloc Function Summary Reallocates a region of memory. Syntax void * JS_realloc(JSContext *cx, void *p, size_t nbytes); Name Type Description cx JSContext * Pointer to a JS context from which to derive runtime information. p void * Pointer to the previously allocated memory nbytes size_t Amount of space, in bytes, to reallocate. Description JS_realloc reallocates a region of memory, while preserving its contents. Typically you call JS_realloc because you need to allocate more memory than orginally allocated with a call to JS_malloc, but it can also be called to decrease the amount of allocated memory, and even to deallocate the memory region entirely. p is a pointer to the previously allocated memory region, and nbytes is the size, in bytes, of the region to allocate. Notes Currently JS_realloc is a wrapper on the standard C realloc call. Do not make assumptions based on this underlying reliance. Future versions of JS_realloc may be implemented in a different manner. If p is null, then JS_realloc behaves like JS_malloc. If p is not null, and nbytes is 0, JS_realloc returns null and the region is deallocated. As with JS_malloc, new space is not initialized and should be regarded to contain meaningless information. If a reallocation request fails, JS_realloc passes cx to JS_ReportOutOfMemory to report the error. Whenever the pointer returned by JS_realloc differs from p, the old region of memory is deallocated and should not be used. JS_MaybeGC Function Summary Invokes conditional garbage collection on the JS memory pool. Syntax void JS_MaybeGC(JSContext *cx); Description JS_MaybeGC performs a conditional garbage collection of JS objects, doubles, and strings that are no longer needed by a script executing in a specified JSContext, cx. This function checks that about 75% of available space has already been allocated to objects before peforming garbage collection. To force garbage collection regardless of the amount of allocated space, call JS_GC instead of JS_MaybeGC. |