• 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: Found It - Problem with Outline View and Manual Memory Management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Found It - Problem with Outline View and Manual Memory Management


  • Subject: Re: Found It - Problem with Outline View and Manual Memory Management
  • From: Dave <email@hidden>
  • Date: Thu, 28 May 2015 14:37:43 +0100

Hi,

This is from Apple Sample Code so I thought something as fundamental as this would have been dealt with correctly. This is the copy method inside the “ImageAndTextCell” class,

-(id) copyWithZone:(NSZone*) zone
{
ImageAndTextCell *cell = (BJImageAndTextCell*) [super copyWithZone:zone];
cell.pTextCellImage = self.pTextCellImage;

return cell;
}

I’ve changed the property to use the copy attribute instead of retain:

@property (nonatomic,copy)	NSImage*					pTextCellImage;


Is this implementation correct? If not what should it be? Something like this?

- (instancetype)initTextCell:(NSString*) theInitialString
{
self = [super initTextCell:theInitialString];
if (self == nil)
	return nil;

self.pTextCellImage = nil;
[self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];

return self;
}

-(id) copyWithZone:(NSZone*) zone
{
ImageAndTextCell *cell = [[[self class] alloc] initTextCell:[self stringValue]];
cell.pTextCellImage = self.pTextCellImage;

return cell;
}

Cheers
Dave

> On 28 May 2015, at 00:25, Graham Cox <email@hidden> wrote:
>
>
>> On 28 May 2015, at 12:56 am, Dave <email@hidden> wrote:
>>
>> myCell = (ImageAndTextCell*) [cell copy];				//*******************************************************************************************************************
>
>
> It’s a “well known”* fact that a copy of an NSCell or any subclass thereof basically doesn’t work. You have to override -copyWithZone: and Do It Properly™, which means NOT calling super’s implementation first (which internally uses NSCopyObject()). I suspect that’s the root cause of your issue.
>
>
> * I say “well known” in quotes because it’s something that lurks there in the frameworks but is never spelt out in documentation, and almost every Mac OS developer comes up against it at some point and has to relearn this fact for themselves. This is your turn.
>
> —Graham
>
>


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Found It - Problem with Outline View and Manual Memory Management
      • From: Kyle Sluder <email@hidden>
References: 
 >Problem with Outline View and Manual Memory Management (From: Dave <email@hidden>)
 >Re: Problem with Outline View and Manual Memory Management (From: Dave <email@hidden>)
 >Found It - Problem with Outline View and Manual Memory Management (From: Dave <email@hidden>)
 >Re: Found It - Problem with Outline View and Manual Memory Management (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Anyone else having trouble with the Provisioning Profile?
  • Next by Date: Re: NSPathControl
  • Previous by thread: Re: Found It - Problem with Outline View and Manual Memory Management
  • Next by thread: Re: Found It - Problem with Outline View and Manual Memory Management
  • Index(es):
    • Date
    • Thread