On Aug 23, 2004, at 5:15 PM, Rick Frankel wrote:
I have created an outline field w/ perl objects as the items. Everything works ok until I dereference the items in either a doubleClick (as in the OutlineView example) or via itemAtRow, at which point the item is corrupted (the objectForItem value is blanked out and a "Bizarre copy of CODE" error is thrown the next time the item is requested in the objectValeForTableColumn selector. If I do a $sender->reloadData in the selector everything is fine, but of course this collapses the outline and looses the selection.
Is this a bug or is there a fundamental reason why perl objects can't be used as outline items?
Short answer: Perl objects can't be used as outline objects.
Long answer: When you pass a Perl object to a Cocoa method, a ObjC stand-in is created, but not retained. Ordinarily, if the receiving object needs access to it later, it retains the passed-in object. NSOutlineView doesn't follow this "cardinal rule" of Cocoa memory management - it needs to access the same objects at a later time, but it doesn't retain them itself.
That's no problem for Cocoa objects - we can simply send them a retain(), or use alloc()->init() to create an object that's been implicitly retained. Although having to remember to send a matching release() when you're done with the object can be a pain - Perl programmers are generally not used to dealing with memory management.
But it's a problem for Perl objects, because the ObjC stand-in cannot be accessed from Perl. It can't be retained unless the Cocoa object it's passed to retains it, which NSOutlineView doesn't do.
sherm--
