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 7649871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:04:51+00:00 2026-05-31T11:04:51+00:00

I am having a very, very strange error, probably related to memory management (even

  • 0

I am having a very, very strange error, probably related to memory management (even though I’m using ARC).

I have a my AppDelegate, Foo, and SubFoo (which is a subclass of Foo).

Foo.h

@protocol FooDelegate <NSObject>

- (void)didReceiveDownloadRequest:(NSURLRequest *)downloadRequest;

@end

@interface Foo : NSObject {
    __weak id <FooDelegate> delegate;
}

- (void)performRequest;

@property (nonatomic, weak) id <FooDelegate> delegate;
@property (nonatomic, retain) NSString *fileIdentifier;

Foo.m

@implementation Foo

@synthesize delegate, fileIdentifier;

- (id)init {
    if ((self = [super init])) {
        self.delegate = nil; // I tried leaving this line out, same result.
        NSLog(@"I am %p.", self);
    }

    return self;
}

- (void)performRequest {
    // Bah.
}

@end

SubFoo.h

@interface SubFoo : Foo {
    WebView *aWebView;
}

SubFoo.m

- (void)performRequest {
    if (self.fileIdentifier) {
        aWebView = [[WebView alloc] init];
        [aWebView setFrameLoadDelegate:self];
        [[aWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"theURL"]];
    }
}

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
    NSLog(@"Finished loading.");

    // ...

    NSLog(@"Class Name: %@", NSStringFromClass([self class]));
    NSLog(@"Memory Location of delegate: %p", self.delegate);

    // ...
}

Sometimes, the class name on webView:didFinishLoadForFrame: returns a completely different class (instead of SubFoo, it returns random classes, like NSSet, NSArray, it even sometimes returns CFXPreferencesSearchListSource), other times it just crashes there with an EXC_BAD_ACCESS, and when it returns a random class on Class Name: it returns that [randomClassName delegate] is an unrecognized selector.

EDIT: When self gets set to another thing, it gets set RIGHT on webView:didFinishLoadForFrame:, and on performRequest it is ALWAYS SubFoo.

Any help here would be appreciated.

  • 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-31T11:04:52+00:00Added an answer on May 31, 2026 at 11:04 am

    First, even though you are using ARC zeroing weak references in your project (@property (weak)), other projects and frameworks may not be (and are probably not) using zeroing weak references.

    In other words, assume that all delegates in frameworks are __unsafe_unretained unless:

    1. The delegate property is declared weak in a header
    2. The documentation/header explicitly states otherwise

    That said, let’s talk about your example. Your object ownership chart looks something like this:

    Object ownership chart

    (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)

    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 __unsafe_unretained. Due to run loop interaction, the WebView is outliving SubFoo. The web request completes, and a dead pointer is dereferenced.

    To fix this, you need to call [aWebView setFrameLoadDelegate:nil]; in SubFoo’s dealloc method. You also need to call it when you reassign aWebView, as you are losing track of the old aWebView:

    SubFoo.m

    @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 {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having a very strange problem, i have a complicated view that returns incorrect
I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call
So I'm having a very strange error right now. I found where it happens,
I'm having strange error with installing fixture from dumped data. I am using psycopg2,
Having a very strange issue regarding postback in ASP.NET. I have page dynamically populating
I'm having a very strange error. I run a perl script which executes linux
I'm having issues with a very strange error in some code I wrote. The
I am having a very strange issue in an activity using a listview that
I am having some very strange ListView behavior when using a StateListDrawable as the
Very strange error I have, I am getting request as null when I try

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.