Next: , Previous: , Up: mpg-bpr   [Contents][Index]


11.3.89 garbage_collect/0

Synopsis

garbage_collect

Invokes the garbage collector.

Description

This predicate invokes the garbage collector to reclaim data structures on the Prolog stack that are no longer accessible to the computation.

Examples

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).

Tips

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.

Exceptions

None.

See Also

ref-mgc.


Send feedback on this subject.