Heap garbage collection is automatically included in XSB [10,23]. (To change the algorithm used for heap garbage collection or to turn it off altogether, see the predicate garbage_collection/1 or Section 3.7 for command-line options). In Version 3.0 the default behavior is indirect garbage collection. Starting with Version 3.0, heap garbage collection may automatically invokes garbage collection of XSB's atom table, which stores Prolog's atomic constants. Expansion and garbage collection of execution stacks can occur when multiple threads are active; however atom garbage collection will not be invoked if there is more than one active XSB thread.
The program area (the area into which XSB byte-code is loaded) is also dynamically expanded as needed. For dynamic code (created using assert/1, or the standard predicates load_dyn/1 and load_dync/1) index size is also automatically reconfigured. Space reclaimed for dynamic code depends on several factors. If there is only one active thread, space is reclaimed for retracted clauses and abolished predicates as long as (1) there are no choice points that may backtrack into the retracted or abolished code, and (2) if the dynamic predicate is tabled, all of its tables are completed. Otherwise, the code is marked for later garbage collection. If more than one thread is active, private predicates behave as just described, however space reclamation for shared predicates will be delayed until there is a single active thread. See Section 6.13 for details.
Space for tables is dynamically allocated as needed and reclaimed through use of the predicates abolish_all_tables/0, abolish_table_pred/1, abolish_table_call/1 and other predicates. As with dynamic code, space for tables may be reclaimed immediately or marked for later garbage collection depending on whether choice points may backtrack into the abolished tables, on the number of active threads, etc. See Section 6.14.3 for details.