Re: Garbage collector - ccl:terminate (memory stuff)
Ron Garret <[email protected]> Mon, 20 May 2024 13:33:24 -0700
| Newsgroups | gmane.lisp.openmcl.devel |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_1DC3EFB1-5ACB-4771-A3D1-6B616CA69083 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On May 20, 2024, at 11:28 AM, Tim McNerney <[email protected]> wrote: >=20 > 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 --Apple-Mail=_1DC3EFB1-5ACB-4771-A3D1-6B616CA69083 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; = charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><br = class=3D""><div><blockquote type=3D"cite" class=3D""><div class=3D"">On = May 20, 2024, at 11:28 AM, Tim McNerney <<a = href=3D"mailto:[email protected]" class=3D"">[email protected]</a>> = wrote:</div><br class=3D"Apple-interchange-newline"><div class=3D""><meta = http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8" = class=3D""><div dir=3D"auto" class=3D"">My question had more to do with = is the CL GC even <i class=3D"">allowed</i> to call back into Lisp code = during collection?</div></div></blockquote><div><br = class=3D""></div><div>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.</div><div><br = class=3D""></div><blockquote type=3D"cite" class=3D""><div class=3D""><div= dir=3D"auto" class=3D""><div class=3D"">Impressive that CCL has these = advanced GC hooks. I stick by my admonition never to call <b = class=3D"">make-instance</b> inside <b = class=3D"">finalize</b>.</div></div></div></blockquote><div><br = class=3D""></div><div>Avoiding memory allocation in general inside a = finalize method is probably good advice. But here's a fun = experiment:</div><div><div><br class=3D""></div><div><div><br = class=3D""></div><div>(defclass foo () ())</div><div><br = class=3D""></div><div>(defvar *cnt* 0)</div><div><br = class=3D""></div><div>(defmethod ccl::terminate ((f foo)) = ()</div><div> (incf *cnt*)</div><div> = (terminate-when-unreachable (make-instance 'foo))</div><div> = (terminate-when-unreachable (make-instance 'foo)))</div><div><br = class=3D""></div><div>(terminate-when-unreachable (make-instance = 'foo))</div><div class=3D""><br class=3D""></div><div class=3D"">(loop = (gc) (print *cnt*) (finish-output) (sleep = 0.1))</div></div></div><div><br class=3D""></div><div><br = class=3D""></div><div><br class=3D""></div><div>Be sure all your files = are saved before running this code.</div><div><br = class=3D""></div><div>rg</div><div><br = class=3D""></div></div></body></html>= --Apple-Mail=_1DC3EFB1-5ACB-4771-A3D1-6B616CA69083--