4.43.1 Garbage collection
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Memory Management
          • Garbage collection
            • garbage_collect/0
            • garbage_collect_atoms/0
            • garbage_collect_clauses/0
            • set_prolog_gc_thread/1
            • trim_stacks/0
            • set_prolog_stack/2
            • prolog_stack_property/2
    • Packages
Availability:built-in
Sourceset_prolog_stack(+Stack, +KeyValue)
Set a parameter for one of the Prolog runtime stacks. Stack is one of local, global or trail. The table below describes the Key(Value) pairs.

Current settings can be retrieved with prolog_stack_property/2.

min_free(+Cells)
Minimum amount of free space after trimming or shifting the stack. Setting this value higher can reduce the number of garbage collections and stack-shifts at the cost of higher memory usage. The amount is reported and specified in cells. A cell is 4 bytes in the 32-bit version and 8 bytes on the 64-bit version. See address_bits. See also trim_stacks/0 and debug/0.
low(+Cells)
factor(+Number)
These two figures determine whether, if the stacks are low, a stack shift (expansion) or garbage collection is performed. This depends on these two parameters, the current stack usage and the amount of stack used after the last garbage collection. A garbage collection is started if used > factor × lastused + low.
spare(+Cells)
All stacks trigger overflow before actually reaching the limit, so the resulting error can be handled gracefully. The spare stack is used for print_message/2 from the garbage collector and for handling exceptions. The default suffices, unless the user redefines related hooks. Do not specify large values for this because it reduces the amount of memory available for your real task.

Related hooks are message_hook/3 (redefining GC messages), prolog_trace_interception/4 and prolog_exception_hook/4.