• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask, alloc but no release?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSTask, alloc but no release?
      • From: "Tom Harrington" <email@hidden>
References: 
 >NSTask, alloc but no release? (From: "Tom Harrington" <email@hidden>)

  • Prev by Date: NSTask, alloc but no release?
  • Next by Date: Re: Best practice for Core Data "ordered" NSArray problem?
  • Previous by thread: NSTask, alloc but no release?
  • Next by thread: Re: NSTask, alloc but no release?
  • Index(es):
    • Date
    • Thread