1

I use a .xib to layout my viewController and have 10 IBOutlet objects that IB uses, none of them have @properties assigned to them (no @property(retain) IBOutlet...). When I release the viewController none of those objects are being released, I have to manually release them in the dealloc of the viewController.

This doesn't seem like normal behavior, I thought that those objects would be released by the system since IB is whats assigning them, what could I be doing wrong?

1 Answer 1

1

Apple's Memory Management Programming Guide tells you exactly how to properly release IBOutlets.

In short, you are supposed to release them in dealloc, but you also want to release them in viewDidUnload.

3
  • Ah, is this new behavior in 4.x now that we have a viewDidUnload and it used to just handle it for you in 3.x?
    – Shizam
    Oct 3, 2010 at 1:09
  • They are assigned to your ivars, so you own them, so you have to release them. This has always been the case. In the past, Leaks didn't detect certain kinds of garbage (it would never detect a leaked UIImageView); perhaps they fixed this. I also highly recommend using properties and using self.foo = nil instead; I cringe when I see code which releases ivars without setting them to nil.
    – tc.
    Oct 3, 2010 at 1:27
  • Thanks, and agreed re: setting things to nil.
    – Shizam
    Oct 3, 2010 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.