1. Module (chicken gc)
    1. gc
    2. current-gc-milliseconds
    3. memory-statistics
    4. set-finalizer!
    5. force-finalizers
    6. set-gc-report!

Module (chicken gc)

This module provides some control over the garbage collector.


[procedure] (gc [FLAG])

Invokes a garbage-collection and returns the number of free bytes in the heap. The flag specifies whether a minor (#f) or major (#t) GC is to be triggered. If no argument is given, #t is assumed. An explicit #t argument will cause all pending finalizers to be executed.


[procedure] (current-gc-milliseconds)

Returns the number of milliseconds spent in major garbage collections since the last call of current-gc-milliseconds and returns an exact integer.


[procedure] (memory-statistics)

Performs a major garbage collection and returns a three element vector containing the total heap size in bytes, the number of bytes currently used and the size of the nursery (the first heap generation). Note that the actual heap is actually twice the size given in the heap size, because CHICKEN uses a copying semi-space collector.


[procedure] (set-finalizer! X PROC)

Registers a procedure of one argument PROC, that will be called as soon as the non-immediate data object X is about to be garbage-collected (with that object as its argument). Note that the finalizer will not be called while interrupts are disabled. This procedure returns X.

Finalizers are invoked asynchronously, in the thread that happens to be currently running. Finalizers for data that has become garbage are called on normal program exit. Finalizers are not run on abnormal program exit. A normal program exit does not run finalizers that are still reachable from global data.

Multiple finalizers can be registered for the same object. The order in which the finalizers run is undefined. Execution of finalizers may be nested.


[parameter] (force-finalizers)

If true, force and execute all pending finalizers before exiting the program (either explicitly by exit or implicitly when the last toplevel expression has been executed). Default is #t.


[procedure] (set-gc-report! FLAG)

Print statistics after every GC, depending on FLAG. A value of #t shows statistics after every major GC. A true value different from #t shows statistics after every minor GC. #f switches statistics off.

Previous: Module (chicken format)

Next: Module (chicken io)