Next: mpg-ref-garbage_collect_atoms, Previous: mpg-ref-functor, Up: mpg-bpr [Contents][Index]
garbage_collect/0
garbage_collect
Invokes the garbage collector.
This predicate invokes the garbage collector to reclaim data structures on the Prolog stack that are no longer accessible to the computation.
In the code fragment:
cycle(X) :- big_goal(X, X1), cycle(X1).
if cycle/1
is to run for a long time, and if big_goal/2
generates a lot of garbage, then rewrite the code like this:
cycle(X) :- big_goal(X, X1), !, garbage_collect, cycle(X1).
Use of the ‘!, garbage_collect’ idiom is only desirable when you notice that your code does frequent garbage collections. It will allow the garbage collector to collect garbage more effectively, and the cycle will run without demanding increasing amounts of memory.
None.