Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 336
Camsoft Avatar asked Dec 22 '22 01:12

Camsoft


2 Answers

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.

like image 119
JiaYow Avatar answered Mar 16 '23 00:03

JiaYow


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

like image 27
flainez Avatar answered Mar 16 '23 01:03

flainez