[Openmcl-devel] slime, cocoa, autorelease

Ben Hyde bhyde at pobox.com
Wed Feb 3 22:49:59 UTC 2010

On Feb 3, 2010, at 11:20 AM, Ben Hyde wrote:
> It appears that the slime/swank REPL could use an auto release pool  
> added to it's dynamic extent.   Anybody already on top of that?
> Note that you'd only notice this if your keeping an eye on the  
> background stream.
> "2010-02-03 11:12:25.458 dx86cl64[55185:22903] ***  
> _NSAutoreleaseNoPool(): Object 0x13a8b120 of class Cat autoreleased  
> with no pool in place - just leaking
> Stack: (0x7fff8159f1e8 0x7fff814b7771 0x1b324)"

Here's what I did.  Patch is to current slime HEAD.   The first bit  
just move a macro earlier to avoid a compile warning.

Then I redefine swank-backend::spawn to wrap the thread in an auto  
reclaim pool, binding that to ccl::*listener-autorelease-pool* ... I  
haven't puzzled out how to get the top level commands like :kap to  
work in the slime listener though.

I have no idea how credible this is, how to get this folded into the  
slime trunk, or if that's a wise move.

  - ben

$ cvs diff -u swank-ccl.lisp
Index: swank-ccl.lisp
RCS file: /project/slime/cvsroot/slime/swank-ccl.lisp,v
retrieving revision 1.13
diff -u -r1.13 swank-ccl.lisp
--- swank-ccl.lisp	3 Jan 2010 15:58:29 -0000	1.13
+++ swank-ccl.lisp	3 Feb 2010 22:41:05 -0000
@@ -434,6 +434,9 @@
                       (format stream " ~s" arg)))))
        (format stream ")"))))

+(defmacro with-frame ((p context) frame-number &body body)
+  `(call/frame ,frame-number (lambda (,p ,context) . ,body)))
  (defimplementation frame-call (frame-number)
    (with-frame (p context) frame-number
      (with-output-to-string (stream)
@@ -446,9 +449,6 @@
         (funcall if-found p context)))

-(defmacro with-frame ((p context) frame-number &body body)
-  `(call/frame ,frame-number (lambda (,p ,context) . ,body)))
  (defimplementation frame-var-value (frame var)
    (with-frame (p context) frame
      (cdr (nth var (ccl:frame-named-variables p context)))))
@@ -728,8 +728,13 @@
    (queue '() :type list))

  (defimplementation spawn (fun &key name)
-  (ccl:process-run-function (or name "Anonymous (Swank)")
-                            fun))
+  (flet ((process-function ()
+           #+apple-objc (let ((ccl::*listener-autorelease-pool*  
+                          (unwind-protect
+                               (funcall fun)
+                            (ccl::release-autorelease-pool  
+           #-apple-objc (funcall fun)))
+    (ccl:process-run-function (or name "Anonymous (Swank)") #'process- 

  (defimplementation thread-id (thread)
    (ccl:process-serial-number thread))

More information about the Openmcl-devel mailing list