[Openmcl-devel] slime, cocoa, autorelease

Gary Byers gb at clozure.com
Wed Feb 3 18:00:14 PST 2010


If I understand correctly, there's no point in trying to implement
the standard REPL's autorelease-pool-related toplevel commands in
SLIME (at least under SLIME's default "communication style".)

In a Cocoa listener thread (or the original bistener thread in the
hybrid (REQUIRE "COCOA") environment) an autorelease pool us created
at thread startup; autoreleased objects are added to this pool when no
more recently-established dynamic pool is in effect.  Some toplevel
commands can be used to examine this global pool's contents and to
release the global pool and its contents and establish a new one.  (I
-think- that it's the case that the global pool is released when the
thread exits.)  This isn't quite the same as running inside a
WITH-AUTORELEASE-POOL, but it keeps things from completely leaking
(and suppesses those warning messages.)

When SLIME/SWANK is using the "spawn" communication style, each
form entered into a SLIME REPL is executed in a separate thread. 
(I have no idea why, but it does exercise all of the timing screws
that can occur when threads exit and exposes some current bugs with
thread cleanup on Windows ...).  The single global autorelease pool
per thread model can't work in that approach  and the REPL commands
for dealing with that global pool wouldn't be meaningful.

I think that your patch is correct for the "spawn" style, which is
apparently the default.  I don't know if other styles are supported
or what the issues would be in those cases.

On Wed, 3 Feb 2010, Ben Hyde wrote:

> 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)))
>     frame-number))
>
> -(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*
> (ccl::create-autorelease-pool)))
> +                          (unwind-protect
> +                               (funcall fun)
> +                            (ccl::release-autorelease-pool
> ccl::*listener-autorelease-pool*)))
> +           #-apple-objc (funcall fun)))
> +    (ccl:process-run-function (or name "Anonymous (Swank)") #'process-
> function)))
>
>  (defimplementation thread-id (thread)
>    (ccl:process-serial-number thread))
> bash-3.2$
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list