Re: Memory leaks with NSAppleScript

  • In related information, a Leopard bug fix in underlying code fixes a
    known memory leak in NSAppleScript's executeAndReturnError:

    Steve

    On Oct 15, 2007, at 12:03 PM, <cocoa-dev-request...> wrote:

    > Message: 1
    > Date: Mon, 15 Oct 2007 14:04:14 +0100
    > From: has <hengist.podd...>
    > Subject: Re: Memory leaks when running an apple event
    > To: <cocoa-dev...>
    > Message-ID: <14DDAC6B-99A4-4BE7-890F-E730C5F2AD3C...>
    > Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
    >
    > Alex Bumbu wrote:
    >
    >> Thanx for the reply. I've made the modifications u've recomended to
    >> me but
    >> the problem still exists. I've found that the
    >> NSAppleEventDescriptor *result
    >> consumes the memory, but if i try to release it the application
    >> will crash.
    >
    > As-per Cocoa memory management rules, the NSAppleEventDescriptor
    > returned by [NSAppleScript -executeAndReturnError:] is autoreleased
    > and will be dealloced when the current autorelease pool is disposed
    > of. Don't release it yourself or you'll get a memory error when the
    > autorelease pool tries to release it when it's already been dealloced.
    >
    > As for the leaks you're currently observing, I would hazard those are
    > coming from NSAppleScript itself. Google 'NSAppleScript memory leak'
    > for similar discussions.
    >
    > Other comments:
    >
    > 1. Your script doesn't change between calls, so you only really need
    > to create a single NSAppleScript instance, assign it to a static
    > variable and reuse it each time. That may or may not minimise the
    > leakage, depending on exactly where it's coming from.
    >
    > 2. If your application is intended for public use you should really
    > avoid scripting the Finder where possible, since not all OS X users
    > will have it running and those that don't (e.g. Path Finder users)
    > won't appreciate you launching it. e.g. Use System Events Process
    > Suite instead.
    >
    > 3. If you want to script applications from ObjC+Cocoa, take a look at
    > objc-appscript <http://appscript.sourceforge.net/objc-appscript.html>
    > which provides a high-level wrapper around the Apple Event Manager
    > API, avoiding the AppleScript language and its related headaches
    > completely.
    >
    > 4. Using application scripting to check for a running process is
    > unnecessarily complex; just use NSWorkspace or the Carbon Process
    > Manager.
    >
    > HTH
    >
    > has
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today