On 15 Nov 2013, at 08:41, Jerry Krinock <je...@ieee.org> wrote: > Several years ago, I subclassed NSPopUpButtonCell and am using it as a table > header cell, so the user can select which attribute is displayed in the > column. Maybe this was not a good idea, but anyhow… > > A few years ago, I noticed a rare, unreproducible bug in my app wherein this > cell would receive -drawWithFrame:inView:, but the value of self is > *different* than the original value of self, which I'd stored in an instance > variable during the -init of this instance. Weird! (I added this instance > variable for the purpose of debugging this problem.) The cell then gets a > -dealloc message, again with the “new self" shortly thereafter, and I’ve > worked around the crashes which would ensue by no-opping these methods if > self != the original self. It does leak, of course.
NSCell declares conformance to the NSCopying protocol. Your subclass has to, too, If you don’t, it will just do a memberwise copy of the instance variables by default, meaning you get a new instance of your class that references the same instance variable contents, but only one of them ever retained it. Implement -copyWithZone: correctly so it copies all those values and ivars, and the problem will go away. Cheers, -- Uli Kusterer “The Witnesses of TeachText are everywhere...” http://zathras.de _______________________________________________ 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