我的旧UIWebViews在使用ARC时似乎仍然存在,由于某些原因,即使我退出UIViewController之后,它们仍会出现在OSX Safari的开发人员工具中。

我正在分配到包含UIWebView的视图控制器的过渡,如下所示:

    //Create settings view/tabbar
    UITabBarController *tabController = [[NoRotateTabBarController alloc] init] ;

    StyleViewController *styleTab = [[StyleViewController alloc] initWithNibName:@"StyleViewController" bundle:nil];
    styleTab.tabBarItem.title = @"Style";
    styleTab.tabBarItem.image = [UIImage imageNamed:@"EyeIcon.png"];

    NSArray *tabsArray = @[styleTab];
    tabController.viewControllers = tabsArray;

    prevView = self.window.rootViewController;

    [UIView
        transitionWithView:self.window
        duration:0.5
        options:UIViewAnimationOptionTransitionFlipFromRight
        animations:^(void) {
            BOOL oldState = [UIView areAnimationsEnabled];
            [UIView setAnimationsEnabled:NO];
            self.window.rootViewController = tabController;
            [UIView setAnimationsEnabled:oldState];
        }
    completion:nil];

我从这种观点出来:
    [UIView
        transitionWithView:self.window
        duration:0.5
        options:UIViewAnimationOptionTransitionFlipFromLeft
        animations:^(void) {
            BOOL oldState = [UIView areAnimationsEnabled];
            [UIView setAnimationsEnabled:NO];
            self.window.rootViewController = prevView;
            [UIView setAnimationsEnabled:oldState];
        }
    completion:nil];

UIWebView(int StyleViewController)是通过以下方式创建的:
    @implementation StyleViewController
    UIWebView *webView;

    //viewDidLoad
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
    webView.scalesPageToFit = NO;
    webView.scrollView.scrollEnabled = false;
    webView.multipleTouchEnabled = false;
    webView.alpha = 0;
    webView.backgroundColor = [UIColor clearColor];
    webView.opaque = false;

    @end

但是,我注意到,当我在Safari中进行检查时,旧的UIWebViews似乎正在堆积,而旧的UIWebViews仍显示在菜单中。这是Safari开发人员工具中的错误吗?有没有办法确保我的UIWebViews被释放?

最佳答案

问题是代表。我使用的是WebViewJavascriptBridge,它对委托人做了一些时髦的事情,所以我需要先摆脱它。在我的viewWillDisappear选择器中执行此操作可避免保留它们:

- (void) viewWillDisappear:(BOOL)animated { /* or dealloc */
    [super viewWillDisappear:animated];

    _bridge = nil;

    //UIWebView #1
    [webView removeFromSuperview];
    webView.delegate = nil; webView = nil;

    //UIWebView #2
    [textView removeFromSuperview];
    textView.delegate = nil; textView = nil;
}

谢谢您提供的所有出色答案,无论如何!

关于iphone - ARC-UIWebView/UIViewController是否在内存中停留?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16347469/

10-11 20:03