Reference count when adding UIView to UIWindow

Discussion in 'iOS Programming' started by SlowMagic, Sep 16, 2008.

  1. SlowMagic macrumors newbie

    Joined:
    Sep 5, 2008
    #1
    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
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    From the docs:
     

Share This Page