5

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?

4

2 回答 2

5

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.

于 2012-12-30T09:29:37.070 回答
0

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.

于 2012-12-30T09:47:16.197 回答