• 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: 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


  • Follow-Ups:
    • Re: Why does this leak memory?
      • From: Bob Ippolito <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>)
 >Re: Why does this leak memory? (From: glenn andreas <email@hidden>)

  • Prev by Date: Two sheets related questions
  • Next by Date: Re: Why does this leak memory?
  • Previous by thread: Re: Why does this leak memory?
  • Next by thread: Re: Why does this leak memory?
  • Index(es):
    • Date
    • Thread