Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>No, you dont have to do that. Just release <code>viewController</code> and it will release all of its <code>subviews</code> internally. Rest will be taken care by framework.</p> <p>If you are not using ARC, your code will look like this,</p> <pre><code>UIViewController *viewController = [[UIViewController alloc] init]; UIView *view1 = [[UIView alloc] init]; [viewController.view addSubview:view1]; [view1 release]; [viewController release]; </code></pre> <p>Since you have allocated both <code>viewController</code> and <code>view1</code> once, you have to release it once as shown above. You dont have to do a release again since you are not doing any <code>retain</code> on this after that.</p> <p>If you do this,</p> <pre><code>UIView *view = (UIView *)[[viewController.view subviews] objectAtIndex:0]; [view release]; </code></pre> <p>It will mostly result in a crash when <code>viewController</code> is released since you are releasing it twice and <code>viewController's</code> subviews are also getting released internally.</p> <p>Here once thing you have to note is that, <code>addSubview</code> retains <code>view1</code> as mentioned in <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html" rel="nofollow">Apple documentation.</a></p> <blockquote> <p>The view to be added. This view is retained by the receiver. After being added, this view appears on top of any other subviews.</p> </blockquote> <p>This will be released once <code>viewController</code> is released and you dont have to manually release it since you dont own it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload