Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-11-2011, 04:20 PM   #3 (permalink)
myok12
Registered Member
 
Join Date: Feb 2011
Posts: 1
myok12 is on a distinguished road
Default

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.
myok12 is offline   Reply With Quote
 

» Advertisements
» Online Users: 397
10 members and 387 guests
7twenty7, antonwilliams, Arty Tales, DaveDee, erdinc27, eski, Lily.P, networ, roof44, ryantcb
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,594
Threads: 94,084
Posts: 402,779
Top Poster: BrianSlick (7,990)
Welcome to our newest member, kopmlop
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:06 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.