A garbage collector that employs the train algorithm determines whether
futile collections have been occurring or the number of trains has
reached a maximum. When either situation occurs, it merges a plurality of
existing trains into a single new train. If the collector detects futile
collection, it merges the oldest train with one of the other trains. If
the number of trains reaches a maximum, the collection so merges trains
that the next train addition will not cause the number of trains to
exceed the maximum.