Comment 1 for bug 1154385

Revision history for this message
James M. Lawrence (llmjjmll) wrote :

This is the nature of conservative gcs; it is only related to Lisp insofar as SBCL and ECL have conservative gcs. When there is a boundlessly growing list as in your example, a cons may eventually be retained by the gc, whereupon infinite storage will be required. This is the "false positive" mentioned in

http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29#Precise_vs._conservative_and_internal_pointers

The solution is to break the chain by replacing

(setq front (cdr front))

with

(setf front (prog1 (cdr front)
              (setf (cdr front) nil)))

For performance reasons this should be probably done even in CL implementations that don't have a conservative gc, as it can significantly reduce a gc's workload.