NSTask, alloc but no release?
NSTask, alloc but no release?
- Subject: NSTask, alloc but no release?
- From: "Tom Harrington" <email@hidden>
- Date: Mon, 1 Oct 2007 10:37:12 -0600
Does NSTask (sometimes) violate the general rule that, if you -alloc
an object, you must then -release it? The example below allocates an
NSTask and registers for a termination notification. When the
notification is received, it releases the NSTask. Since the NSTask
was -alloc'ed, that would seem to be necessary, but doing so makes the
app crash.
It looks as though the NSTask is getting autoreleased, but where? I'd
expect that if I was using -launchedTaskWithLaunchPath:arguments:, but
not for -alloc. The NSTask documentation doesn't give any hints that
-release is a bad idea here, but apparently it is.
- (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];
}
--
Tom Harrington
email@hidden
AIM: atomicbird1
_______________________________________________
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