Previous: , Up: Data Types   [Contents][Index]

5.3.7 Garbage Collection

In Lisp, data objects are used very freely; a side effect of this is that it is not possible to (easily) know when an object is stale, that is, no references to it exist and it can therefore be reused.

The garbage collector is used to overcome this problem; whenever enough memory has been allocated to make it worthwhile, evaluation stops and the garbage collector works its way through memory deciding which objects may still be referenced, and which are stale. The stale objects are then recorded as being available for reuse and evaluation continues. (But see Guardians)

Function: garbage-collect

Runs the garbage collector, usually this function doesn’t need to be called manually.

Variable: garbage-threshold

The number of bytes of data that must have been allocated since the last garbage collection before evaluation pauses and the garbage collector is invoked. Its default value is about 100K.

Variable: idle-garbage-threshold

When the input loop is idle (due to a lack of input), this is the number of bytes of data that must have been allocated since the garbage collection, for another collection to be triggered.

This is usually set to a lot less than garbage-threshold since the small delay caused by garbage collection is unnoticeable if the system is already idle.

Variable: after-gc-hook

A hook (see Normal Hooks) called immediately after each invocation of the garbage collector.