Objects that are known to have long life can be allocated directly in a higher generation, by using
allocation-in-gen-num
and
set-default-generation
. Note that both these functions have a global effect, i.e. any object allocated after a call to
set-default-generation
or within the body of
allocation-in-gen-num
is allocated in the specified generation, unless it is explicitly allocated in a different generation. Therefore careless use of these functions may lead to allocation of ephemeral garbage in high generations, which is very inefficient. Conversely, if a long-lasting object is allocated to a low generation, it has to survive several garbage collections before being automatically promoted to the next generation.
See also Allocation of interned symbols and packages and Allocation of stacks.