Re: Why does this leak memory?
Re: Why does this leak memory?
- Subject: Re: Why does this leak memory?
- From: Bob Ippolito <email@hidden>
- Date: Mon, 11 Jul 2005 13:08:53 -1000
On Jul 11, 2005, at 5:51 AM, glenn andreas wrote:
On Jul 11, 2005, at 10:40 AM, Matt Ball wrote:
Interface:
#import <Cocoa/Cocoa.h>
@interface LayerCell : NSTextFieldCell
{
NSImage *image;
}
- (NSImage *)image;
@end
Implementation of NSCopying:
- (id)copyWithZone:(NSZone *)zone
{
NSCell *copy = [[[self class] alloc] init];
return copy;
}
This does not implement copy correctly - the results are a new
object that doesn't have an image, so it's not a copy of the original.
You'll need to do something more like:
- (id)copyWithZone:(NSZone *)zone
{
LayerCell *copy = [[[self class] alloc] init];
[copy setImage: [self image]];
return copy;
}
I'm pretty sure you want to be calling the super implementation of
copyWithZone:, but then you have another problem (probably, anyway).
See here:
http://www.mulle-kybernetik.com/weblog/archives/000472.html
-bob
_______________________________________________
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