This article covers features introduced in SpiderMonkey 1.8
Enable GC zeal, a testing and debugging feature that helps find GC-related bugs in JSAPI applications.
void JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency);
||A context. The GC zeal level of the associated
||The desired level of garbage collection.|
||With some zeal levels, a GC is triggered every
JS_SetGCZeal sets the level of additional garbage collection to perform for a runtime, for the purpose of finding or reproducing bugs.
There are several different levels which have different functions:
|0||Normal amount of collection. The default: no additional collections are performed.|
|1||Collect when roots are added or removed.|
|2||Collect when every
|3||Collect on window paints.|
|4||Verify pre write barriers between instructions.|
|5||Verify pre write barriers between window paints.|
|6||Verify stack rooting.|
|7||Collect the nursery every
|8||Incremental GC in two slices: 1) mark roots 2) finish collection.|
|9||Incremental GC in two slices: 1) mark all 2) new marking and finish.|
|10||Incremental GC in multiple slices.|
|11||Verify post write barriers between instructions.|
|12||Verify post write barriers between paints.|
|13||Check internal hashtables on minor GC.|
|14||Perform a shrinking collection every
Regularly running your test suite with GC zeal enabled at level 2 is a good practice.
This function is available only in
DEBUG builds. To enable this function in an optimized build, define the macro
JS_GC_ZEAL building SpiderMonkey.
(In a debug build of Gecko, you can also set the current GC zeal level using the