ARC dealloc best pratice
ARC dealloc best pratice
- Subject: ARC dealloc best pratice
- From: Jonathan Mitchell <email@hidden>
- Date: Fri, 06 Feb 2015 14:48:48 +0000
I have a mid sized (200+ nib files and associated NSView + NSWindow controllers) ARC enabled app.
I have Zombie objects ON and have chased down a number of issues, most of which can be traced back to an incorrectly defined dealloc.
My recent experiences have demonstrated the treacherous nature of these sorts of issues.
One development machine seemed impervious to an issue, another exhibited it with unfailing regularity.
So I want to have a best practice template to follow in my dealloc.
At present the template looks like so. When I need a dealloc I paste this in and fill in the blanks
- (void) dealloc
{
// remove observers
// remove any explicit bindings
// unregister for notifications
// set any non-weak delegates to nil (NSTableView et al)
// invalidate any timers
}
In particular I have issues with non weak delegates and making sure that I get them set to nil.
I am not aware of anyway of automatically analyzing the source to help ensure that I haven’t missed something.
Are the following correct:
1. I presume that all the Cocoa framework objects such as NSTableView, NSPopOver etc that have non weak delegates need set to nil (in other words - AppKit doesn’t use ARC).
2. This applies even if I don’t have an outlet to say a NSTableView - which effectively means that I have to have outlets to all such objects.
3. At present I have not tried to ensure that NSWindow delegates (typically NSWindowController instances) are nil. Should I?
Jonathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden