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
garbage_collect_clauses
Reclaim retracted clauses. During normal operation, retracting a clause implies setting the erased generation to the current generation of the database and increment the generation. Keeping the clause around is both needed to realise the logical update view and deal with the fact that other threads may be executing the clause. Both static and dynamic code is processed this way.164Up to version 7.3.11, dynamic code was handled using reference counts..

The clause garbage collector (CGC) scans the environment stacks of all threads for referenced dirty predicates and at which generation this reference accesses the predicate. It then removes the references for clauses that have been retracted before the oldest access generation from the clause list as well as the secondary clauses indexes of the predicate. If the clause list is not being scanned, the clause references and ultimately the clause itself is reclaimed.

The clause garbage collector is called under three conditions, (1) after reloading a source file, (2) if the memory occupied by retracted but not yet reclaimed clauses exceeds 12.5% of the program store, or (3) if skipping dead clauses in the clause lists becomes too costly. The cost of clause garbage collection is proportional with the total size of the local stack of all threads (the scanning phase) and the number of clauses in all‘dirty' predicates (the reclaiming phase).