Re: How is this an "incorrect decrement of a reference count"?
Re: How is this an "incorrect decrement of a reference count"?
- Subject: Re: How is this an "incorrect decrement of a reference count"?
- From: Roland King <email@hidden>
- Date: Tue, 20 Mar 2012 08:15:42 +0800
On Mar 20, 2012, at 7:27 AM, G S wrote:
> Yep, thanks. Someone pointed that out.
>
> I went through my whole project and audited every file for memory management, reinstating properties for everything. After forgetting not to use properties in the init and dealloc methods and having to correct that, the app is running great and there's not a leak to be found.
>
> That reminds me of another question, though: Someone earlier mentioned the need to release elements loaded from the nib, in dealloc. I didn't think this was necessary, so I don't do it. And there are no apparent leaks as a result. What's the story on that?
Elements loaded from NIBs and just displayed in the view hierarchy don't need to be released (only their superview retains them so they are released as the view is destroyed). If you store them also into properties (IBOutlets) then those properties need to be released in dealloc just like other properties, which you probably do anyway. For UIViewControllers you should also implement viewDidUnload and set those IBOutlet properties to nil else those objects you don't need are retained until the next time the view is loaded which rather ruins the point of the low-memory code.
If you are using ARC then you can just make the properties weak and whenever the view goes away, the IBOutlet's go away too, very useful.
I think most of this is in the NIB loading guide and the template code for UIViewController subclases (and the code auto-generated when you add outlets in Xcode using the mouse) does this.
_______________________________________________
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