<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">It is interesting to contemplate using a terminate method to create a (mythologically reincarnated) “baby Phoenix” object that never has any pointers to it, thus guaranteed it will “burn” (get reclaimed) upon the very next GC. <div><br></div><div>It is unlikely that this use case has been well tested. More to the point: it is unwise, if not explicitly disallowed, to <i>cons</i> in a terminate method. When the GC is running, one must assume to be in a situation where there is <i>zero</i> available memory. (This prudent restriction is more likely to be a stumbling block when inserting debugging statements in memory management code.)<div><br></div><div>Curious… what does Common Lisp <i>in general</i> have to say about the GC calling terminate methods? I must confess that while intriguing, I haven’t thought about this corner of storage management engineering since the 80’s. </div><div><br></div><div>Keep thinking good thoughts. <br><div><br id="lineBreakAtBeginningOfSignature"><div dir="ltr">--Tim</div><div dir="ltr"><br><blockquote type="cite">On May 20, 2024, at 05:19, Robert Munyer <2420506348@munyer.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><span>While I was waking up, I had a strange thought (possibly left</span><br><span>over from a dream) about a way to implement a counter that lives</span><br><span>in "unreachable" heapspace, and is repeatedly destroyed by the</span><br><span>garbage collector, but continues counting anyway.</span><br><span></span><br><span>Code:</span><br><span></span><br><span> (defclass garbage-counter () ((n :initarg :n)))</span><br><span></span><br><span> (defmethod initialize-instance :after</span><br><span> ((x garbage-counter) &rest initargs)</span><br><span> (declare (ignore initargs))</span><br><span> (ccl:terminate-when-unreachable x))</span><br><span></span><br><span> (let ((s *terminal-io*))</span><br><span> (defmethod ccl:terminate ((x garbage-counter))</span><br><span> (let ((n (1+ (slot-value x 'n))))</span><br><span> (make-instance 'garbage-counter :n n)</span><br><span> (format s "~&garbage-counter: ~s~%" n)</span><br><span> (finish-output s))))</span><br><span></span><br><span>Usage example:</span><br><span></span><br><span> ? (progn (make-instance 'garbage-counter :n 0) t)</span><br><span> T</span><br><span> ? (ccl:gc)</span><br><span> NIL</span><br><span> ?</span><br><span> garbage-counter: 1</span><br><span> (ccl:gc)</span><br><span> NIL</span><br><span> ?</span><br><span> garbage-counter: 2</span><br><span></span><br><span>Greg, I had no difficulty getting this to work in FriCAS's "BOOT"</span><br><span>package; it worked on the first try. I'll attach a transcript,</span><br><span>in case seeing exactly what I did might be useful to you.</span><br><span></span><br><div><transcript.txt></div></div></blockquote></div></div></div></body></html>