Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:25:09+00:00 2026-05-22T15:25:09+00:00

I am implementing a simple in-app browser. In my home view ( UITableViewController ),

  • 0

I am implementing a simple in-app browser. In my home view (UITableViewController), I have something like:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

        WebViewController *webViewController = [[WebViewController alloc] init];
        switch (indexPath.row) {
            case 0:
                webViewController.stringURL = @"http://www.google.com";
                break;
            case 1:
                webViewController.stringURL = @"http://www.bing.com";
                break;
            default:
                webViewController.stringURL = @"http://stackoverflow.com"; 
                break;
        }

        [self.navigationController pushViewController:webViewController animated:YES];
        [webViewController release];
    }

The app crashed after I repetitively navigated back and forth between my home view and webViewControllera few times.

Inside WebViewController class, I have nothing but a [UIWebView *webView] and a [UIActivityIndicatorView *activityIndicator]. Both are with attributes nonatomic, retain. Here is the implementation.

        #import "WebViewController.h"
        @implementation WebViewController
        @synthesize webView, activityIndicator, stringURL;

        - (void)dealloc
        {
            [self.webView release];
            self.webView.delegate = nil;
            [self.activityIndicator release]; 
            [super dealloc];
        }

        -(void)loadView {
            UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
            self.view = contentView;    

            CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
            webFrame.origin.y = 0.0f;
            self.webView = [[UIWebView alloc] initWithFrame:webFrame];
            self.webView.backgroundColor = [UIColor blueColor];
            self.webView.scalesPageToFit = YES;
            self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
            self.webView.delegate = self;
            [self.view addSubview: self.webView];
            [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.stringURL]]];

            self.activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            self.activityIndicator.frame = CGRectMake(0.0, 0.0, 30.0, 30.0);
            self.activityIndicator.center = self.view.center;
            [self.view addSubview: self.activityIndicator];
        }

        - (void)viewDidLoad
        {   
            [super viewDidLoad];
            [self loadView];
        }

        - (void)webViewDidStartLoad:(UIWebView *)webView
        {
            // starting the load, show the activity indicator in the status bar
            [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
            [activityIndicator startAnimating];
        }

        - (void)webViewDidFinishLoad:(UIWebView *)webView
        {
            // finished loading, hide the activity indicator in the status bar
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            [activityIndicator stopAnimating];
        }

        @end

I just ran my app in Instruments using the Zombies template, which shows -[UIWebView webView:didReceiveTitle:forFrame:] is the Zombie call. But I still can’t figure out what is actually the problem.

(Please download trace if needed)

Any help is greatly appreciated!

[Update]:

  1. As @7KV7 and @David pointed out, there is an obvious bug in my dealloc function. I should call self.webView.delegate=nil; first before I release self.webView. Sorry about that. Unfortunately, after I fix it, the app still crashes in the same way.
  2. If I delete [webViewController release]; from the first code block, the crash actually is gone. But obviously, there will be memory leak.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:25:09+00:00Added an answer on May 22, 2026 at 3:25 pm

    First of all, remove that call to loadView in viewDidLoad. The framework will the call the method when it doesn’t find a view provided in XIB file. Second, your loadView is filled with memory leaks. You are allocating, initializing and retaining an object every time the method is called. So you are taking ownership twice and releasing it only once in the dealloc.

    The objects are not being properly deallocated. You should do something like alloc-init-autorelease to solve this. Next thing is the that every time the controller gets loaded, because of your call to loadView, you end up creating two web view objects and two requests. You lose reference to one of them as you reassign. Herein, lies the problem mentioned in the title. You aren’t able to reset the delegate of a web view object that has your controller as a delegate. Imagine a request being completed soon after you leave. Here the message will go to a zombie object. This is a pretty good example for why you need to nil out your delegates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a very simple file database. I have 2 basic operations: void
I'm implementing simple drag-and-drop functionality in my app, and I would like to know
I'm implementing a very simple audio-only RTMP server. I have my client code like
I am implementing a simple version of a linux shell in c. I have
I have a simple webapp in Django for an iPhone app. I want to
Probably a simple question. I have an interface (MyInterface) that defines a property like
Hey I just had a simple question about implementing landscape mode for an app,
I'm developing my first iPhone app, and while implementing user preferences, I have a
I'm Implementing a simple web app using Django, I want to get user's location
I'm using node, express and connect for a simple app and have basic HTTP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.