Camsoft
Camsoft

Reputation: 12005

Should I release instance variables and properties in dealloc?

According to Apple's documentation on the View Controller Lifecycle I noticed the following regarding the dealloc method:

Override this method only to perform any last-minute cleanup of your view controller class. Objects stored in instance variables and properties are automatically released; you do not need to release them explicitly.

I've been taught always to call release on instance variables and properties that I own in my view controller's dealloc method.

The only exception I was aware of is when using ARC but it does not mention ARC in this documentation.

Is this correct?

Upvotes: 4

Views: 1127

Answers (2)

flainez
flainez

Reputation: 11847

As JiaYow mentions, that guide has been updated to ARC. Here you can find the Legacy guide for view controllers: https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerPGforiOSLegacy/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP40011381-CH101-SW1

Upvotes: 2

JiaYow
JiaYow

Reputation: 5227

Since the guide you posted was updated recently, I'm pretty sure that it assumes you're using ARC (you should do that, after all, if possible).

You're correct, before ARC, you had to release your instance variables in the dealloc method (you can see that in the old XCode templates in the dealloc of the App-Delegate). With ARC, this gets handled automatically (as this guide says), so except for special needs, the dealloc method is not used anymore.

Upvotes: 9

Related Questions