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

2015-05-29 Thread Dave

 On 28 May 2015, at 17:56, Kyle Sluder k...@ksluder.com wrote:
 
 On Thu, May 28, 2015, at 08:37 AM, Dave wrote:
 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'm guessing this is taken from the SourceView sample? That project uses
 ARC. If you are using ARC in your own project, sending -copyWithZone: to
 super should do the right thing. (Yes, whether super does the right
 thing is based on whether _your class_ is compiled using ARC.)
 
 In any event, please consider moving to a view-based table view. Then
 you don't need to use a custom cell class at all.
 
 --Kyle Sluder

SourceView is ARC based, but the project I extracted the View Controller and 
Utility Classes into is non ARC. Given that the project is non-ARC, is the 
copyWithZone method above valid? 

 In any event, please consider moving to a view-based table view. Then
 you don't need to use a custom cell class at all.

I probably will at some point, but I’d like to get this working ok first, 
although it seems ok at the moment.

Cheers
Dave


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2015-05-28 Thread Dave
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 graham@bigpond.com wrote:
 
 
 On 28 May 2015, at 12:56 am, Dave d...@looktowindward.com 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2015-05-28 Thread Kyle Sluder
On Thu, May 28, 2015, at 08:37 AM, Dave wrote:
 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'm guessing this is taken from the SourceView sample? That project uses
ARC. If you are using ARC in your own project, sending -copyWithZone: to
super should do the right thing. (Yes, whether super does the right
thing is based on whether _your class_ is compiled using ARC.)

In any event, please consider moving to a view-based table view. Then
you don't need to use a custom cell class at all.

--Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Found It - Problem with Outline View and Manual Memory Management

2015-05-27 Thread Dave
Hi,

I’ve Found it, please see line marked below.

In I change this to:

myCell = (ImageAndTextCell*) [cell copy];   
//***

It doesn’t work, which is a bit of a mystery? Because of this, I think there is 
something wrong somewhere else which copying and releasing here is 
working-around the problem, rather than solving at source?

I assume that in the Source Project, under ARC, the value was retained 
auto-magically?

Thanks Again,
Dave



- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell*)cell 
forTableColumn:(NSTableColumn *)tableColumn item:(id) item
{
NSImage*iconImage;
NSString*   urlStr;
ImageAndTextCell*   myCell;
ChildNode*  myChildNode;

if ([[tableColumn identifier] isEqualToString:COLUMNID_NAME] == NO)
return;

if ([cell isKindOfClass:[ImageAndTextCell class]] == NO)
return;

myChildNode = [item representedObject];
if (myChildNode == nil)
return;

if ([myChildNode class] != [ChildNode class])
return;

myCell = (ImageAndTextCell*) [cell copy];   
//***
myCell.pTextCellImage = nil;
iconImage = nil;

if (myChildNode.isLeaf == YES)
{
urlStr = myChildNode.urlString;
if (urlStr != nil)
{
if ([myChildNode.urlString hasPrefix:HTTP_PREFIX] == YES)
{
myChildNode.nodeIcon = self.pURLImage;
}
else
{
iconImage = [[NSWorkspace sharedWorkspace] 
iconForFile:urlStr];
myChildNode.nodeIcon = iconImage;
}
}
}

//**
//**Check if it's a special folder (PLACES or BOOKMARKS), we don't want it 
to have an icon
//**
else
{
if ([self isSpecialGroup:myChildNode] == YES)
{
myChildNode.nodeIcon = nil;
}
else
{
myChildNode.nodeIcon = self.pFolderImage;
}
}


[myChildNode.nodeIcon setSize:NSMakeSize(kIconImageSize,kIconImageSize)];

iconImage = myChildNode.nodeIcon;
myCell.pTextCellImage = iconImage;

[myCell release];
}



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Found It - Problem with Outline View and Manual Memory Management

2015-05-27 Thread Dave
Sorry, I meant:

In I change this to:

myCell = (ImageAndTextCell*) [cell retain]; 
//***

It doesn’t work? Presumably now I think about it, because the Image property is 
not retained when I do a retain. When I use copy, it increases the retain count 
by 1.

All the Best
Dave


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

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

2015-05-27 Thread Graham Cox

 On 28 May 2015, at 12:56 am, Dave d...@looktowindward.com 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com