5.2 Storage allocation
When you create a reference to a Lisp object, you normally store a pointer to that object. For example, the following expression creates a list and binds the list to a variable:
(setq newlist (list 'a 'b 'c))The variable name is a symbol stored in the static area whose value cell points to the first element of the list. The list itself is a chain of cons cells created in the dynamic or ephemeral space whose cars point to elements of the list and whose cdrs point to successive cons cells in the list.
Lisp manipulates objects by manipulating pointers; if an object no longer has pointers to it, it becomes inaccessible. For example, the following expression changes the value of the variablenewlist
:
(setq newlist (list 'd 'e 'f))The symbol in the static area now points to a new object in dynamic space. If there are no other pointers to the list
(a b c)
, the object that was the variable's previous value, that list is inaccessible even though it continues to take up space in memory.Garbage collection eliminates inaccessible objects from the dynamic or ephemeral space so that there is room to create new objects. The two garbage-collecting programs in Lisp are described in Section 5.3 on page 81.
Generated with Harlequin WebMaker