Re: Why does this leak memory?
Re: Why does this leak memory?
- Subject: Re: Why does this leak memory?
- From: glenn andreas <email@hidden>
- Date: Mon, 11 Jul 2005 10:51:19 -0500
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;
}
Copy is suppose to have all the same value/properties/behavior that
the original has, and so without this, all the later code that does
things like:
NSDivideRect (aRect, &imageFrame, &textFrame, 10 + [[self image]
size].width, NSMinXEdge
is going to fail because there is no image for that copy (returning
undefined values for -(NSSize) size).
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Widgetarium | the quickest path to widgets
_______________________________________________
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