Re: NSTask, alloc but no release?
Re: NSTask, alloc but no release?
- Subject: Re: NSTask, alloc but no release?
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 1 Oct 2007 09:47:51 -0700
On Oct 1, 2007, at 9:37 AM, Tom Harrington wrote:
- (void)taskComplete:(NSNotification *)note
{
NSTask *theTask = [note object];
NSLog(@"termination status: %d", [theTask terminationStatus]);
[theTask release];
}
- (IBAction)runTask:(id)sender
{
NSTask *theTask = [[NSTask alloc] init];
[theTask setLaunchPath:@"/bin/ls"];
[theTask setArguments:[NSArray arrayWithObjects:@"-lR", @"/private/
tmp", nil]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskComplete:)
name:NSTaskDidTerminateNotification
object:theTask];
[theTask launch];
}
It likely doesn't explain the crash, but a quick read of your code
indicates that you need to remove 'self' as an observer of the
'NSTaskDidTerminateNotification' notification prior to releasing the
task.
NSNotificationCenter is not self cleaning, nor does it retain all
objects that are involved in notifications. Not removing
notification observers is a very large source of crashers in Cocoa
applications.
b.bum
_______________________________________________
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