Re: Memory leaks when running an apple event
Re: Memory leaks when running an apple event
- Subject: Re: Memory leaks when running an apple event
- From: has <email@hidden>
- Date: Mon, 15 Oct 2007 14:04:14 +0100
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
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden