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. :)
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 mails | Author | Date |
|---|---|---|
| Jonathan Dann | Jan 27, 03:09 | |
| James Bucanek | Jan 27, 16:37 | |
| Jonathan Dann | Jan 27, 23:06 | |
| Quincey Morris | Jan 27, 23:51 | |
| Quincey Morris | Jan 28, 00:18 | |
| James Bucanek | Jan 28, 01:35 | |
| Shripada Hebbar | Jan 28, 05:32 |






Cocoa mail archive

