• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I get rid of this warning message?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I get rid of this warning message?


  • Subject: Re: How can I get rid of this warning message?
  • From: Charles Srstka <email@hidden>
  • Date: Mon, 21 Jan 2013 14:44:02 -0600

On Jan 21, 2013, at 2:20 PM, Rick Aurbach <email@hidden> wrote:

> I am attempting to use the RTPTimer wrapper that Gordon Apple contributed to this list. (Thanks, Gordon!)
>
> It appears to work great, but I find that the class's executeSelector: method generates a warning message.
>
>> - (void) executeSelector:(NSTimer*)timer {
>>   if(self.target != nil) {
>>       if([self.target respondsToSelector:self.sel])
>>           [self.target performSelector:self.sel withObject:self];
>>   }
>>   else
>>       [self invalidate];
>> }
>
> where sel is defined as @property(nonatomic) SEL sel;
>
> The line containing the performSelector:withObject: method generates
> "PerformSelector may cause a leak because its selector is unknown".
>
> Ok, I agree that the selector is unknown, but we know from the previous line that the target responds to it. So I'd like to prevent this particular warning. I'm sure I ought to know how do do this, but how do I go about removing this warning message? Ideally, I'd like to do this on a file (or occurrence) basis, so that I can make sure that other similar usages are similarly safe.

The reason it gives that warning is because you're using ARC. Because ARC uses selector naming conventions to determine certain behaviors, such as whether an object returned from a method should be retained or not, if ARC doesn't know what selector is actually being used here, it doesn't know how it should manage memory for any object returned from this method, conceivably resulting in crashes or leaks.

I'd suggest you have a look at dispatch_after instead of NSTimer — it uses a more modern blocks-based interface instead of the old target/selector stuff, which is often easier to use than target/selector as well as being more flexible and compatible with both ARC and Xcode's Refactor feature (it's very annoying to refactor a method only to get unexpected runtime exceptions later because something was calling the method via @selector, and the refactor process didn't pick it up).

Charles

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How can I get rid of this warning message? (From: Rick Aurbach <email@hidden>)

  • Prev by Date: RE: How can I get rid of this warning message?
  • Next by Date: Re: How can I get rid of this warning message?
  • Previous by thread: RE: How can I get rid of this warning message?
  • Next by thread: Re: How can I get rid of this warning message?
  • Index(es):
    • Date
    • Thread