Skip navigation.
 
mlRe: Running an NSTask Within an NSThread
FROM : Quincey Morris
DATE : Sun Jan 27 23:51:04 2008

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. :)

Related mailsAuthorDate
mlRunning an NSTask Within an NSThread Jonathan Dann Jan 27, 03:09
mlRe: Running an NSTask Within an NSThread James Bucanek Jan 27, 16:37
mlRe: Running an NSTask Within an NSThread Jonathan Dann Jan 27, 23:06
mlRe: Running an NSTask Within an NSThread Quincey Morris Jan 27, 23:51
mlRe: Running an NSTask Within an NSThread Quincey Morris Jan 28, 00:18
mlRe: Running an NSTask Within an NSThread James Bucanek Jan 28, 01:35
mlRe: Running an NSTask Within an NSThread Shripada Hebbar Jan 28, 05:32