name: duk_gc proto: | void duk_gc(duk_context *ctx, duk_uint_t flags); summary: |
Force a mark-and-sweep garbage collection round. If mark-and-sweep is disabled in the Duktape build, the call is a no-op.
The following flags are defined:
Define | Description |
---|---|
DUK_GC_COMPACT | Force object property table compaction |
You may want to call this function twice to ensure even objects with finalizers are collected. Currently it takes two mark-and-sweep rounds to collect such objects. First round marks the object as finalizable and runs the finalizer. Second round ensures the object is still unreachable after finalization and then frees the object.
example: | duk_gc(ctx, 0); tags: - memory - heap introduced: 1.0.0