[Openmcl-devel] Garbage collector - ccl:terminate (memory stuff)

Ron Garret ron at flownet.com
Mon May 20 13:33:24 PDT 2024


> On May 20, 2024, at 11:28 AM, Tim McNerney <mc at media.mit.edu> wrote:
> 
> My question had more to do with is the CL GC even allowed to call back into Lisp code during collection?

Of course.  What would be the point otherwise?  But I think what you really meant to ask is whether finalization methods are allowed to allocate memory.

> Impressive that CCL has these advanced GC hooks. I stick by my admonition never to call make-instance inside finalize.

Avoiding memory allocation in general inside a finalize method is probably good advice.  But here's a fun experiment:


(defclass foo () ())

(defvar *cnt* 0)

(defmethod ccl::terminate ((f foo)) ()
  (incf *cnt*)
  (terminate-when-unreachable (make-instance 'foo))
  (terminate-when-unreachable (make-instance 'foo)))

(terminate-when-unreachable (make-instance 'foo))

(loop (gc) (print *cnt*) (finish-output) (sleep 0.1))



Be sure all your files are saved before running this code.

rg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20240520/3f3f55bc/attachment.htm>


More information about the Openmcl-devel mailing list