On 8/9/12 12:58 AM, Graham Cox wrote:
NSCell apparently uses NSCopyObject() to make a copy of itself, and NSTableView copies cells at times, e.g. for hit testing. If you have a custom cell subclass that supports copying, DO NOT use [super copyWithZone:] followed by your custom copy stuff. Since super uses NSCopyObject, any pointer ivars that your custom cell has added has get copied verbatim, (unretained) and then if you set a property on the copy that releases the old pointer, it is now overreleased. Shortly afterwards this will cause an EXC_BAD_ACCESS crash. I thought the modern advice was to avoid NSCopyObject() like the plague for this reason, though I notice that Cocoa still does use it itself (particularly NSImage and NSImageRep).
Not calling super sounds like a bad idea. If you set the ivars of your copy in -copyWithZone: that should really not be a problem, it doesn't matter if super set them or not. The unretained references will get replaced by whatever you choose to do with the ivar in your copy (copy, retain).
It works fine in a number of custom cells I use (used in outline views and tables). Regards Markus -- __________________________________________ Markus Spoettl _______________________________________________ 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