Object release in Objective-C: Why release an object twice in viewDidUnload and dealloc method? -
Objective-I have a question about the release of the object. I saw some sample code in chapter 9 of "Safing iPhone 4 Development" (p. 287). The sample code releases an object twice: both viewDownload and Deloop method. Here are sample codes:
- (zero) viewDidUutup {self.list = zero; [ChildController release], childController = nil;} - (zero) DLock {[release list]; [Child Controller Release]; [Super Delooc];} Child Controller has been declared as an example of the UIViewController subclass, both of it Why is the ViewDidInloadload and Deloop method released? Since childController is already being released in viewDidUnload , is it necessary to reissue it in the dealloc method? Based on my understanding, I will write the code:
- (zero) viewDiduude {self.list = zero; ChildController = Zero;} - (Zero) Dailyock {[Release list]; [Child Controller Release]; [Super DeLoc];} Thanks, Sam
< P> The problem is that every time such as the dealloc method is not guaranteed to be called (check) viewDidUnload . viewDidUnload is the reason for releasing the object in order to avoid memory leaks. Since viewDidUnload is said to have low memory warning, you want to clear the case to avoid troubles. and zero will not be the cause of any problem, so it is considered safe to release calls to objects placed in their dealloc method Standards are set in the form of zero (such as viewDidUnload in your example) after being released at other locations.
Comments
Post a Comment