Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top