Re: Unidentified Nib'ed Instance
Re: Unidentified Nib'ed Instance
- Subject: Re: Unidentified Nib'ed Instance
- From: Glenn Andreas <email@hidden>
- Date: Sat, 27 Mar 2004 09:11:56 -0600
At 10:26 PM -0800 3/26/04, Seth Willits wrote:
In my NSDocument subclass (MyDocument) I have a reference to a
custom class that wraps all of the data of the document (MyData). In
the init method of MyDocument I create and initialize MyData by:
mMyData = [[MyData alloc] init];
[mMyData retain];
You're over-retaining it here - since you created the instantance
with alloc/init, it is already retained (or, alternately, it hasn't
been auto-released).
(BTW if someone can refresh me how to make init a class method that
allocs and does all of the typical stuff I would want it to, I'd
appreciate it, but if it's more than five lines I wouldn't bother -
I'll look around and find it.)
@implementation MyData
+ (MyData *) myData
{
return [[[self alloc] init] autorelease];
}
@end
(OK, 6 lines, and since the factory method returns an auto-released
object, you want to retain it)
--
Glenn Andreas email@hidden
mondo blobbo, Cythera, Theldrow, oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.