Static area memory leak (?)
[LWW 4.4.5 on WinXP pro SP2.]
Compile and load the following code:
(defun octets-to-string (octets &optional (external-format :latin-1))
(let* ((octet-count (length octets))
(vector (sys:in-static-area
(make-array octet-count
:element-type '(unsigned-byte 8)
:initial-contents octets))))
(fli:with-dynamic-lisp-array-pointer
(ptr vector)
(fli:convert-from-foreign-string ptr
:external-format external-format
:length octet-count
:null-terminated-p nil))))
(defun foo (n)
(dotimes (i n)
(octets-to-string #(228 246 252))))
I can observe the following behaviour:
CL-USER 1 > (room)
Generation 0: Total Size 3722K, Allocated 379K, Free 3326K
Generation 1: Total Size 3074K, Allocated 898K, Free 2159K
Generation 2: Total Size 10196K, Allocated 8399K, Free 1785K
Generation 3: Total Size 17720K, Allocated 17148K, Free 555K
Total Size 34710K, Allocated 26825K, Free 7826K
CL-USER 2 > (foo 100)
NIL
CL-USER 3 > (room)
Generation 0: Total Size 63882K, Allocated 3977K, Free 59884K
Generation 1: Total Size 3074K, Allocated 898K, Free 2159K
Generation 2: Total Size 10196K, Allocated 8399K, Free 1785K
Generation 3: Total Size 17720K, Allocated 17151K, Free 553K
Total Size 94870K, Allocated 30426K, Free 64382K
CL-USER 4 > (foo 100)
NIL
CL-USER 5 > (room)
Generation 0: Total Size 120842K, Allocated 7427K, Free 113394K
Generation 1: Total Size 3074K, Allocated 898K, Free 2159K
Generation 2: Total Size 10196K, Allocated 8399K, Free 1785K
Generation 3: Total Size 17720K, Allocated 17153K, Free 550K
Total Size 151830K, Allocated 33878K, Free 117889K
Note the rapid growth of generation 0. At the same time one can see
(using a tool like "Process Explorer") that the amount of "private
bytes" reserved by the LW executable grows enormously and doesn't
shrink again.
It is my understanding from the reference entry for IN-STATIC-AREA
that VECTOR above is subject to normal garbage collection and the
amount of free space shown by ROOM seems to confirm that. However,
why does the executable grow irreversibly? What can be done about
this?
Thanks,
Edi.