Generally, whenever you release your ownership, you should also clear your reference.
So, two options, if you don't need any reference to your object after it has been created and added to the UI, you can just release and set the reference to nil. You don't need to do anything in the load's tearing down, or in the dealloc since you already released your ownership. In this case, you actually don't need an instance variable to reference it; a local variable will do. The UI still maintains ownership over the object (when you added it to as a subview) and will maintain it as long a the UI is shown.
On the other hand, in case you do need to hold a reference to the object throughout the UI's lifetime (for example to be able to update it), then the instance variable is correct. In this case, however, you should not release your ownership in the viewDidLoad and instead do that in the tearing down (and also set the reference to nil) and in the dealloc.
Since you are releasing your ownership and setting the reference to nil in the tearing down process, the dealloc one will do nothing; but it's still needed in case the tearing down process is skipped (allowed in iOS); in this case, the dealloc will release your ownership.
|