[Openmcl-devel] Fix memory leak in an objc example

Paul Krueger plkrueger at comcast.net
Wed Apr 30 15:32:36 PDT 2014


Leo,

It may be that what you think is a memory leak is just a consequence of Lisp garbage collection not running between loop iterations. If you want to test that, put an explicit call (gc) inside that loop and see if the "leak" goes away.

What does (all-applications) do? If you're doing some objective-C stuff there then unless you are explicitly calling #/release on everything you #/alloc, then that might be causing a problem as well. Many Objective-C apps use automatic garbage collection rather than explicit memory management using release calls, but you cannot do that inside CCL. Lisp does not do any automatic garbage collection for Objective-C objects; it relies on the objective-c runtime code to do that when appropriate #/release calls are made (or #/autorelease if you take care to set up an autorelease pool to make that work). There are other memory management issues to understand if you create Lisp classes that inherit from Objective-C classes, but I presume that you aren't doing that.

Paul

On Apr 30, 2014, at 3:05 PM, Leo Liu <sdl.web at gmail.com> wrote:

> Hi there,
> 
> I was able to put together this small example (with lots of help from
> #ccl irc channel). However it is leaking memory. To see it, load the
> attached memleak.lisp file and run
> 
>  (loop repeat 10 do (all-applications))
> 
> The memory use (observed in Activity Monitor) increases > 2M for every
> run. Could someone help? General tips on memory management using the
> objc-bridge is also very welcome.
> 
> Thanks in advance,
> Leo
> 
> <memleak.lisp>_______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://lists.clozure.com/mailman/listinfo/openmcl-devel




More information about the Openmcl-devel mailing list