Re: Why does this leak memory?
Re: Why does this leak memory?
- Subject: Re: Why does this leak memory?
- From: Matt Ball <email@hidden>
- Date: Mon, 11 Jul 2005 11:40:34 -0400
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;
}
That stops the crash from occurring, but now I can no longer edit my
cell. This is my custom editing code:
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView
editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent
*)theEvent
{
NSRect textFrame, imageFrame;
NSDivideRect (aRect, &imageFrame, &textFrame, 10 + [[self image]
size].width, NSMinXEdge);
textFrame.origin.y = NSMinY(textFrame) + textFrame.size.height/4 + 2;
textFrame.size.height = 18;
[super editWithFrame:textFrame inView:controlView editor:textObj
delegate:anObject event:theEvent];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView
editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart
length:(int)selLength {
NSRect textFrame, imageFrame;
NSDivideRect (aRect, &imageFrame, &textFrame, 10 + [[self image]
size].width, NSMinXEdge);
textFrame.origin.y = NSMinY(textFrame) + textFrame.size.height/4 + 2;
textFrame.size.height = 18;
[super selectWithFrame:textFrame inView:controlView editor:textObj
delegate:anObject start:selStart length:selLength];
}
- Matt Ball
On 7/11/05, j o a r <email@hidden> wrote:
>
> On 11 jul 2005, at 17.24, Matt Ball wrote:
>
> > I've read through that page and its conceptual counterpart, and I
> > don't see why that is applicable to my situation. The values of a cell
> > are set by the tableView's methods; they do not all have the same
> > values. I'm sure I'm interpreting it wrong, but I don't see how that
> > will help me. I've messed around with the code on that page, and the
> > effect is the same.
>
> 1) A cell subclass used by a table view needs to implement NSCopying
> protocol correctly, because the table view will copy cells from time
> to time.
>
> 2) If you implement support for NSCopying incorrectly, you can end up
> with memory management errors that causes crashes. There is
> information about this problem on the page that I linked to in my
> last message.
>
> We might be able to offer some suggestions if you can provide:
>
> * The interface of your cell subclass
> * The implementation of NSCopying for your cell subclass
>
> I'm not even sure that this is the problem you're seeing, as I don't
> know your current implementation, and since I haven't seen the
> backtrace to your crash.
>
> j o a r
>
>
>
>
>
_______________________________________________
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