ARC - UIWebView/UIViewController is sticking around in memory?

My old UIWebViews seem to be sticking around when using ARC, for some reason they still show up in OSX Safari's Developer Tools even after I've come out of their UIViewController.

I'm allocating an transitioning to a view controller that contains a UIWebView, like this:

    //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];

I'm coming out of that view like this:

    [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];

The UIWebView (int StyleViewController) is being created this way:

    @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

However, I notice that when I inspect in Safari, the old UIWebViews appear to be stacking up, and the old ones still show in the menu. Is this a bug in Safari's Developer tools? Is there a way to ensure that my UIWebViews get released?

Answers


The issue was delegates. I was using WebViewJavascriptBridge, and it does some funky stuff with delegates, so I needed to get rid of it first. Doing this in my viewWillDisappear selector kept them from getting retained:

- (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;
}

Thank you for all the excellent answers, regardless!


Need Your Help

AttributeError: 'NoneType' object has no attribute 'wrap_socket' in GAE using Braintree

python google-app-engine braintree

I am testing an app in the Google App Engine that embeds the Braintree platform. I am using their code for this test to process a fictitious transaction. In my html I have a form that when submitte...

No Source Code is available for type java.text.SimpleDateFormat: GWT Compilation Error

java gwt

I was trying to make a GWT application. Then I got some errors when using SimpleDateFormat class in client and shared side.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.