IOS - release problem when switching UIWindow

I use a context-sensitive key UIWindowin my application to provide a stream with a cleaner stream - welcome window => main screen with a list of items <=> product container with a hamburger menu and more.

Example:

- (void)updateKeyWindow:(UIWindow *)window withTransition:(WindowTransition)transition
{
    UIWindow *originalWindow = _keyWindow;
    _keyWindow = window;

    window.alpha = 0;
    [originalWindow resignKeyWindow];
    [originalWindow resignFirstResponder];
    originalWindow.userInteractionEnabled = NO;
    [window makeKeyAndVisible];
    window.transform = (transition == WindowTransitionFlyDown) ? CGAffineTransformMakeScale(1.02, 1.02) :
                       (transition == WindowTransitionFlyUp)   ? CGAffineTransformMakeScale(.96, .96) :
                                                                 CGAffineTransformIdentity;

//  [UIView animateWithDuration:.24 animations:^{

        window.alpha = 1;
        originalWindow.alpha = 0;
        window.transform = CGAffineTransformIdentity;
        originalWindow.transform = (transition == WindowTransitionFlyDown) ? CGAffineTransformMakeScale(.96, .96) :
                                   (transition == WindowTransitionFlyUp)   ? CGAffineTransformMakeScale(1.02, 1.02) :
                                                                             CGAffineTransformIdentity;

//  } completion:^(BOOL b){

        [originalWindow resignFirstResponder];
        [originalWindow removeFromSuperview];
        [originalWindow.rootViewController.view removeFromSuperview];
        originalWindow.rootViewController = nil;
        originalWindow = nil;

//  }];
}

I use animations to provide nice transitions, but I commented on this to see if this is the cause of the problem I am having.

The fact is that after removal originalWindowfrom the hierarchy and exit from the block / function, it is UIWindow NOT released and hangs somewhere in space. I tested this with a child class, setting a breakpoint inside the overloaded one -dealloc.

UIApplication -keyWindow, AppDelegate -window, UIWindow.

, -dealloc UIWindow -[UITouch dealloc] .

Call stack after clicking inside a new start UIWindow dealloc old UIWindow

, , UIKit - , , - .

+4
1

resignKeyWindow:

. UIWindowDidResignKeyNotification, , ...

, .

-1

All Articles