RE: Why does this leak memory?
RE: Why does this leak memory?
- Subject: RE: Why does this leak memory?
- From: Jeff Laing <email@hidden>
- Date: Tue, 12 Jul 2005 11:22:47 +1000
> Check out this link that was the first hit on google searching for
> "copyWithZone:zone":
>
> http://www.cocoabuilder.com/archive/message/cocoa/2004/11/5/120922
But don't take what it says literally - make sure you read the entire thread
which points out some fatal flaws again to do with reference counting...
*That* is the main reason I hate the way people respond here with 'look
harder next time - I found it in one google hit'. Because so many times
I've found misinformed opinions just as prevalent as informed ones.
Would it really have killed everyone to point out exactly what was wrong
with this code, rather than just say "its bogus, go read the docs properly".
> - (id)copyWithZone:(NSZone *)zone
> {
> LayerCell *copy = [[[self class] alloc] init];
> [copy setImage:[self image]];
> return [super copyWithZone:zone];
> }
For the record, it would look better as
- (id)copyWithZone:(NSZone *)zone
{
LayerCell *copy = [super copyWithZone:zone]; // get superclass to
make a copy
[copy setImage:[self image]]; // then copy
our members across
return copy; //
before returning the copy
}
At least, thats my novice opinion.
_______________________________________________
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