Re: is [[NSObject alloc] release] correct?
Re: is [[NSObject alloc] release] correct?
- Subject: Re: is [[NSObject alloc] release] correct?
- From: Shawn Erickson <email@hidden>
- Date: Mon, 05 Jun 2006 20:21:47 -0700
On Jun 5, 2006, at 8:02 PM, Adam R. Maxwell wrote:
// Pattern A
- (id)initWithObject:(id)anObject
{
[self release];
return [[OtherObject alloc] init];
}
// Pattern B
- (id)initWithObject:(id)anObject
{
[[self init] release];
return [[OtherObject alloc] init];
}
From my reading of the docs, Pattern A is correct in theory.
However, it breaks badly with NSDate, and I'm curious as to whether
Pattern B is needed for only a few cases ([[NSArray alloc] release]
and [[NSString alloc] release] work fine, for instance), or is more
correct.
It isn't safe to assume that you can send a release message to an
uninitialized object since the release method for that class may make
assume that it was initialized (which is the normal situation).
So you either have to call its designated initializer and then
release it or possibly use the foundation function NSDeallocateObject
(id).
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden