Note that the garbage collector is usually triggered automatically, controlled by the user-definable flag gc_interval. Therefore, the usage of garbage_collect/0 should be restricted to situations where the automatic triggering performs badly. In this case it should be inserted in a place where it is known for sure that a lot of structures and lists have become useless, eg. just before a tail-recursive call as shown in the example.
cycle(OldState) :- transform(OldState, NewState), /* long computation */ !, garbage_collect, /* OldState is obsolete */ cycle(NewState).