• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why does this leak memory?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Why does this leak memory?
      • From: Bob Ippolito <email@hidden>
    • Re: Why does this leak memory?
      • From: Matt Ball <email@hidden>
References: 
 >Why does this leak memory? (From: Matt Ball <email@hidden>)
 >Re: Why does this leak memory? (From: Charilaos Skiadas <email@hidden>)
 >Re: Why does this leak memory? (From: Matt Ball <email@hidden>)
 >Re: Why does this leak memory? (From: Charilaos Skiadas <email@hidden>)
 >Re: Why does this leak memory? (From: Matt Ball <email@hidden>)
 >Re: Why does this leak memory? (From: Bob Ippolito <email@hidden>)
 >Re: Why does this leak memory? (From: j o a r <email@hidden>)
 >Re: Why does this leak memory? (From: Matt Ball <email@hidden>)
 >Re: Why does this leak memory? (From: j o a r <email@hidden>)
 >Re: Why does this leak memory? (From: Matt Ball <email@hidden>)

  • Prev by Date: Re: Developing an iPhoto plugin for iPhoto books
  • Next by Date: Re: SOAP Handler question
  • Previous by thread: Re: Why does this leak memory?
  • Next by thread: Re: Why does this leak memory?
  • Index(es):
    • Date
    • Thread