3

Which of the following is correct?

NSTableCellView *cell = [outlineView makeViewWithIdentifier: [tableColumn identifier] owner: self];
// Do stuff…
return cell;

or

NSTableCellView *cell = [[outlineView makeViewWithIdentifier: [tableColumn identifier] owner: self] retain];
// Do stuff…
return cell;

I'm confused because the makeView… method returns an autoreleased view and table view cells can't be released while the table view is still there. Does the table view retain the cell itself?

Thank you a lot!

Constantino Tsarouhas
  • 6,846
  • 6
  • 43
  • 54

1 Answers1

3

Since you don't specify, I assume that this code is from your implementation of the ‑tableView:viewForTableColumn:row: delegate method of NSTableView.

If that's the case then it doesn't matter what the table view does with the cell, because the ownership of the cell is not your problem. Your responsibility is to conform to the memory management rules as implied by the method signature, and in this case the delegate method returns an autoreleased object because it doesn't contain the words new or copy. Thus, you need to return an autoreleased object. In your case, that's the cell instance.

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
  • So, NSTableView retains the cell? (By the way, everything works fine, I just want to be sure.) :-) – Constantino Tsarouhas Aug 13 '11 at 16:30
  • 1
    Well, it probably does, but my point is that it doesn't matter. It's not your responsibility, you just need to fulfil the memory management contract that is implicit in the naming of the method you're implementing. – Rob Keniger Aug 15 '11 at 06:31