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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:09:24+00:00 2026-05-28T04:09:24+00:00

For years I’ve been following a great pattern called Target-Action which goes like this:

  • 0

For years I’ve been following a great pattern called Target-Action which goes like this:

An object calls a specified selector on a specified target object when the time comes to call. This is very useful in lots of different cases where you need a simple callback to an arbitrary method.

Here’s an example:

- (void)itemLoaded {
    [specifiedReceiver performSelector:specifiedSelector];
}

Under ARC it now turns out that doing something like this all of a sudden became dangerous.

Xcode throws a warning that goes like this:

PerformSelector may cause a leak because its selector is unknown

Of course the selector is unknown since as part of the Target-Action design pattern you can specify whatever selector you want in order to get a call when something interesting happens.

What bugs me most about this warning is that it says there can be a potential memory leak. From my understanding ARC doesn’t bend the memory management rules but instead simply automates the insertion of retain/release/autorelease messages at the right locations.

Another thing to note here: -performSelector: does have an id return value. ARC analyzes method signatures to figure out through application of naming conventions if the method returns a +1 retain count object or not. In this case ARC doesn’t know if the selector is a -newFooBar factory or simply calling an unsuspicious worker method (which is almost always the case with Target-Action anyways). Actually ARC should have recognized that I don’t expect a return value, and therefore forget about any potential +1 retain counted return value. Looking at it from that point of view I can see where ARC is coming from, but still there is too much uncertainty about what this really means in practice.

Does that now mean under ARC something can go wrong which would never happen without ARC? I don’t see how this could produce a memory leak. Can someone give examples of situations in which this is dangerous to do, and how exactly a leak is created in that case?

I really googled the hell out of the internet but didn’t find any site explaining why.

  • 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-28T04:09:25+00:00Added an answer on May 28, 2026 at 4:09 am

    The problem with performSelector is that ARC doesn’t know what the selector which will performed, does. Consider the following:

    id anotherObject1 = [someObject performSelector:@selector(copy)];
    id anotherObject2 = [someObject performSelector:@selector(giveMeAnotherNonRetainedObject)];
    

    Now, how can ARC know that the first returns an object with a retain count of 1 but the second returns an object which is autoreleased? (I’m just defining a method called giveMeAnotherNonRetainedObject here which returns something autoreleased). If it didn’t add in any releases then anotherObject1 would leak here.

    Obviously in my example the selectors to be performed are actually known, but imagine that they were chosen at run time. ARC really could not do its job of putting in the right number of retains or releases here because it simply doesn’t know what the selector is going to do. You’re right that ARC is not bending any rules and it’s just adding in the correct memory management calls for you, but that’s precisely the thing it can’t do here.

    You’re right that the fact you’re ignoring the return value means that it’s going to be OK, but in general ARC is just being picky and warning. But I guess that’s why it’s a warning and not an error.

    Edit:

    If you’re really sure your code is ok, you could just hide the warning like so:

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [specifiedReceiver performSelector:specifiedSelector];
    #pragma clang diagnostic pop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For years I have been using the following pattern to remove duplicates from an
Years back I built a simple mail form that has been working like a
For years now I've been using a chat that has the following code to
Years ago I released a program called Banshee Screamer Alarm and at the time
For years I have been using the DEBUG compiler constant in VB.NET to write
For years, maybe 10, I've been fascinated with cryptography. I read a book about
For years I've been using ShellExecute() API to launch the default web browser from
For years I've been reading about XML and I have just not quite grokked
A few years ago I wrote a WCF service, which runs on a Windows
After years of working OK, I'm suddenly getting this message when trying to start

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.