Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, even though you are using ARC zeroing weak references in your project (<code>@property (weak)</code>), other projects and frameworks may not be (and are probably not) using zeroing weak references.</p> <p>In other words, assume that all delegates in frameworks are <code>__unsafe_unretained</code> unless:</p> <ol> <li>The delegate property is declared <code>weak</code> in a header</li> <li>The documentation/header explicitly states otherwise</li> </ol> <hr> <p>That said, let's talk about your example. Your object ownership chart looks something like this:</p> <p><img src="https://i.stack.imgur.com/o1GoQ.png" alt="Object ownership chart"></p> <p>(Note: I'm not entirely sure which class in your project uses SubFoo. Based on common practice, I'm assuming that you have a class with a strong reference to SubFoo, and that class is also set up to be a SubFooDelegate)</p> <p>Ultimately, your instance of SubFoo is losing its last strong reference and is deallocating. In a perfect ARC-enabled world, the WebView's pointer to SubFoo would nil out at this time. However, it's not a perfect world yet, and WebView's frameLoadDelegate is <code>__unsafe_unretained</code>. Due to run loop interaction, the WebView is outliving SubFoo. The web request completes, and a dead pointer is dereferenced.</p> <p>To fix this, you need to call <code>[aWebView setFrameLoadDelegate:nil];</code> in SubFoo's dealloc method. You also need to call it when you reassign aWebView, as you are losing track of the old aWebView:</p> <p>SubFoo.m</p> <pre><code>@implementation SubFoo - (void)dealloc { [aWebView setFrameLoadDelegate:nil]; // Also nil out any other unsafe-unretained references } - (void)performRequest { if (self.fileIdentifier) { [aWebView setFrameLoadDelegate:nil]; // Protects us if performRequest is called twice. Is a no-op if aWebView is nil aWebView = [[WebView alloc] init]; [aWebView setFrameLoadDelegate:self]; [[aWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"theURL"]]; } } - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { // ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload