Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SlowMagic

macrumors newbie
Original poster
Hi all,

I have this piece of code:

UIWindow _window = [UIWindow alloc initWithFrame: http://UIScreen mainScreen].bounds;

_mainViewController = [MainViewController alloc] init;

_window addSubview: _mainViewController.view;
where _mainViewController is subclass of UIViewController.

If I check the reference count of "_mainViewController" after asigning its "view" to "_window", the value returned is "2". Why can "addSubview" message increase the reference count of "_mainViewController"? Shouldn´t "_window" just retain its view instead of the whole object?
Finally, when I try to release "_mainViewController", there reference count never get to 0 even if I release "_window" and "removeFromSuperview" its view.
Why does it behave like this?
Any idea about how I can release "_mainViewController"?

Thanks in advance
 
From the docs:
The receiver retains view. If you use removeFromSuperview to remove view from the view hierarchy, view is released. If you want to keep using view after removing it from the view hierarchy (if, for example, you are swapping through a number of views), you must retain it before invoking removeFromSuperview.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.