This section summarizes Memory Management functionality common to all LispWorks 7.1 implementations.
11.6.2 Reducing image sizeTo reduce the size of the whole image, use clean-down.
In 32-bit LispWorks, you can use (clean-down)
or the less aggressive (clean-down nil)
to reduce the image size when the image is much larger than the amount that is allocated. In 64-bit LispWorks there is no need to do that.
(clean-down t)
promotes to generation 3 and tries to reduce the image size, while (clean-down nil)
promotes only to generation 2 and does not reduce the image size. Experience suggests that the latter is actually more useful in most circumstances.
In some circumstances it is important to avoid enlarging the size of the image even temporarily. The common situation is when the operating system signals low memory. In this situation you should use reduce-memory instead of clean-down.
Interned symbols (and their symbol names), and packages, are treated in a special way, because they are assumed to have a long life. They are allocated in the generation specified by the variable *symbol-alloc-gen-num*, which has the initial value 2 in 32-bit LispWorks and 3 in 64-bit LispWorks.
Symbols created with make-symbol
or gensym
start out in generation 0.
Symbols will be garbage collected if they are no longer accessible (regardless of property lists) but note that in 32-bit LispWorks, if the symbols are in generation 2 then you might need to invoke gc-generation explicitly to collect them in a timely manner.
11.6.4 Allocation of stacksStacks are allocated directly in generation 2 because they are relatively expensive to promote. Therefore creating many processes will cause generation 2 to grow, even if these processes are short-lived.
The variable *default-stack-group-list-length* controls the number of stacks that are cached for reuse. Increase its value if your application repeatedly makes and discards more than 10 processes.
To call a function on all objects in the image, use sweep-all-objects.
Users of the Foreign Language Interface may want to specify the allocation of static arrays. The recommended way to do this is to call make-array
with :allocation
:static
. See for example :lisp-array
in the LispWorks Foreign Language Interface User Guide and Reference Manual .
This section describes techniques that may improve the performance of your application by reducing the GC's workload.
11.6.9.1 Breaking pointers from older objectsThis is a technique that can be useful when older objects regularly point to newer objects in a lower generation. In such a case, when the lower generation (only) is collected these newer objects will be promoted even if the older objects are not live. All of these objects will not get collected until the higher generation is collected.
This is a general issue with generational garbage collection and, if it causes poor performance in your application, can be addressed along these lines. It is not necessarily a problem in every case where older objects point to newer objects.
For example, suppose you are popping items from a queue represented as a list of conses (or other structures), then you can set the "next" slot of each popped item to nil
.
In the code below, if the queue-head
cons is promoted to generation n, then all the other conses will also be promoted to generation n eventually, until generation n is collected. This happens even after calls to pop-queue
have removed these conses from the queue.
(defstruct queue head tail)
(defun push-queue (item queue)
(let ((new (cons item nil)))
(if (queue-head queue)
(setf (cdr (queue-tail queue)) new)
(setf (queue-head queue) new))
(setf (queue-tail queue) new)))
(defun pop-queue (queue)
(pop (queue-head queue)))
The fix is to make pop-queue
set the "next" slot (in this case the cdr
) of the discarded queue-head
cons to nil
, so that it no longer points from an older object to a newer object. For example:
(defun pop-queue (queue)
(when-let (head (queue-head queue))
(setf (queue-head queue) (shiftf (cdr head) nil))
(car head)))
LispWorks User Guide and Reference Manual - 20 Sep 2017
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4