Retaing count is one after release being called
I have a 开发者_如何学JAVAview controller who's views are loaded from a nib file. The nib file contains the main view, which has a scroll view as its subview. Inside view controller's viewDidLoad method, the retain count of the scroll view is 2 (1 for when it was created, and 1 because I retain it). When the view controller's dealloc method is being called, I release the scroll view, but its retain count only decreases to 1, which makes sense since it was 2 at the beginning.
Based on the above scenario, my question is: does the scroll view get fully released after the dealloc method returns, because it is then that the main view is released, forcing all of its subviews (such as the scroll view), to be removed/released? Or, does this release happen at a different point in time?
Thanks!
EDIT: If after I release the scroll view, I set it to nil (while the retain count is still 1), will that scroll view ever get fully released?
It is retained by the superview it is located in, when that superview goes away it will get another release (and so dealloc'd if the retain count goes to zero). If you're curious you could subclass the UIScrollView and put a NSLog or breakpoint in the dealloc function to be sure. Or, run with the Leaks Instrument and see if it's showing up as a leak.
Yes, when you call [super dealloc]
at the end.
精彩评论