Leo Zhang
Leo Zhang

Reputation: 3240

What kind of property should be set to nil in dealloc?

I'm using ARC. Will ARC automatically release all the properties in dealloc? Is it necessary to manual set all public properties and private field to nil? Are there any good pattern to follow?

Upvotes: 5

Views: 703

Answers (2)

tiguero
tiguero

Reputation: 11537

Good question. When using ARC the compiler will implement a dealloc method for you and will handle implicitly the release of your instance variables and properties.

You may still need a custom -dealloc if your class needs to do anything other than releasing memory (e.g unregister for notifications like jrturton mentioned).

You can get a good grasp of what's you need to consider when transitioning to ARC in those Apple official notes.

Upvotes: 0

jrturton
jrturton

Reputation: 119292

Under ARC, the pattern is... don't do anything in dealloc, or even implement it. ARC takes care of your properties and instance variables for you.

The only exception is that dealloc is a good place to unregister for notifications, if your object has registered for any.

Upvotes: 5

Related Questions