[Openmcl-devel] Fix memory leak in an objc example
sdl.web at gmail.com
Wed Apr 30 18:04:06 PDT 2014
On 2014-04-30 17:32 -0500, Paul Krueger wrote:
> 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.
With (ccl:gc) inserted between calls, the increase is 2M.
> 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.
all-applications calls a c function `_LSCopyAllApplicationURLs' which
returns a mutable nsarray of NSURLs. all-applications converts that
nsarray to a list of strings for lisp.
I tried putting a #/autorelease on (ccl:%get-ptr urls) and the memory
leak seems to be gone. Does this mean we always have to release rlet's
> 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.
More information about the Openmcl-devel