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

  • SEARCH
  • Home
  • 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 6234039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:24:36+00:00 2026-05-24T10:24:36+00:00

When running Analyzer, I receive the Object sent -autorelease too many times warning. I

  • 0

When running Analyzer, I receive the “Object sent -autorelease too many times” warning. I know I’m doing something tricky (and am open to alternatives to accomplishing my goal).

Essentially, I wanted to keep a stack of specific types of controllers handy for sending messages from a central location. So, considering:

From ‘ActionBroker’ shared object:

NSMutableSet *liveActions;
liveActions = [NSMutableSet alloc] init];

…

CLViewController *action = [[[actionClass alloc] init] autorelease];
if (!action) {
    return nil;
}    
[self.liveActions addObject: action];
// When adding an object, the retain count is increased. We want the action
// to dealloc, so that it might remove itself from the list...
[action release];
return action;    

And the complementary dealloc code:

[[CLActionBroker sharedActionBroker] removeAction: self];        
[super dealloc];

… and in removeAction:

[action retain];
[self.liveActions removeObject:action];

The above code works, I just get the nagging error. And the nagging sensation that I could probably solve the problem a different way.

One of the use cases for this code is to pass an ‘handleOpenURL’ request through a chain of open controllers and returning the first ‘YES’ response.

  • 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-24T10:24:37+00:00Added an answer on May 24, 2026 at 10:24 am

    As I understand it, your intent is to have a set of controllers (“actions”) in the set, which you could easily access from anywhere in your app. If one of these controllers is deallocated, it would automatically remove itself from the set.

    There’s a problem with this setup, though. As you’ve described it above, the controller is supposed to be removed from the liveActions set upon deallocation. But since an NSSet retains its members, your controller will never be deallocated so long as it is still in the liveActions set. -dealloc is only run when all retains have been balanced by a release.

    This, then leads to your over-release, which leads to the warning. Since you’ve sent an extra release, -dealloc could be run while the controller is still in the liveActions set. But when you remove it from that set, it’s going to send a release message to your object, which would take its retain count negative. That may or may not be safe, but in either case it’s an ugly workaround.

    What you really want, it seems, is a set that does not retain its members. This is normally a dangerous configuration, since it can lead to dangling pointers in the set. But if you’re willing to manage the lifetime of the object and clear out those dangling pointers at the appropriate times, it turns out that it’s quite doable. You just need to use a CFMutableSet instead of an NSMutableSet. And since the two are toll-free bridged, it doesn’t even add that much complexity.

    Setting up the CFMutableSet looks like this:

    // The NULL for the third parameter tells the set to not do anything when
    // an object is added to or removed from the set.
    CFMutableSetRef cfLiveActions = CFSetCreateMutable(NULL, 0, NULL);
    
    // Toll-free bridging makes this possible
    NSMutableSet *liveActions = (NSMutableSet *)cfLiveActions;
    

    After that, you can use it exactly as you would use any other NSMutableSet; this one will just be special in that it won’t retain its members.

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

Sidebar

Related Questions

I have about 500+ memory warnings after running the static analyzer. Is this something
Running the static analyzer on this piece of code: - (id) readForeignPref { CFPropertyListRef
I'm trying to analyze some running times for various methods in my default.aspx.cs page.
Does anybody have any success running clang static analyzer on Windows? I have successfully
I have a complex report running in T-SQL, which in query analyzer was running
I'm running sql analyzer on the following query SELECT bl.Invoice_Number, bl.Date_Invoice, ti.TranNo, bt.Description, CONVERT(decimal(15,2),
I have got python code running on multiple analyzer machines each picking documents from
I am running wireshark build on linux. I get a crash,while doing some activities.
Yes, I know. The existence of a running copy of SQL Server 6.5 in
I am running my application through xcode's static analyzer and it pointed out that

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.