The macro
block-promotion
executes
body
and prevents promotion of objects into generation 2 during this execution. After
body
is executed, generations 0 and 1 are collected.
This is useful when a significant number of transient objects actually survive all the garbage collections on generation 1. These would normally then be promoted and, by default, never get collected. In such a situation,
(mark-and-sweep 2)
will free a large amount of space in generation 2.
block-promotion
can be thought of as doing set-promotion-count on generation 1 with an infinite
count
, for the duration of body.
block-promotion
is suitable only for use in particular operations that are known to create such relatively long-lived, but transient, objects. In typical uses these are objects that live for a few seconds to several hours. An example usage is LispWorks compile-file, to ensure the transient compile-time data gets collected.
block-promotion
has global scope and hence may not be useful in an application such as a multi-threaded server. During the execution of
body
, generation 1 grows to accomodate all the allocated data, which may have some negative effects on the behaviour of the system, in particular on its interactive response.
Note: symbols and process stacks are allocated in generation 2, hence
block-promotion
cannot prevent these getting into generation 2. allocation-in-gen-num can also cause allocation in higher generations.