Re: Running an NSTask Within an NSThread
Re: Running an NSTask Within an NSThread
- Subject: Re: Running an NSTask Within an NSThread
- From: Quincey Morris <email@hidden>
- Date: Sun, 27 Jan 2008 14:51:04 -0800
On Jan 27, 2008, at 14:06, Jonathan Dann wrote:
// NSDocument subclass implementation
- (IBAction)runTask:(id)sender;
{
TaskController *tC = [[TaskController
defaultControllerForDocument:self];
[tC performTask];
}
...
This currently adheres to the memory management conventions, ...
Er, no, it doesn't. The (correctly autoreleased) TaskController has
reference count 0, so is subject to disappearance anytime (for all
practical purposes) after you return from runTask. What you really
need to is make tC an instance variable of your document subclass,
change runTask to say:
tC = [[[TaskController defaultControllerForDocument:self] retain];
and find a suitable place for the TaskController to tell the document
to release it (e.g. in taskDidTerminate). You also need to make sure
that the document gets rid of any leftover TaskController in its
dealloc, as well as in any other cases where the TaskController is not
going to clean up after itself.
Or you could start using garbage collection and get an extra half
hour's sleep tonight. :)
_______________________________________________
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