Reputation: 8944
I am using the below code & i am getting warning as
Perform selector may cause leak because select is unknown
Code
SEL _selector = NSSelectorFromString([[arrEffects objectAtIndex:1] valueForKey:@"method"]);
self.mainImageView.image = [self.mainImage performSelector:_selector];
Please tell me who can i get rid of this warning?
Upvotes: 0
Views: 886
Reputation: 52538
You fix it by getting rid of this awful code. To whoever thought this code was a good idea: No, it's not. It's an attempt at being clever and failing miserably.
You are storing the name of a method somewhere in an array, which is totally unsafe. I recommend you analyse the code, find which selectors are possibly stored, and instead of this awful code you store a block which takes an image as a parameter and returns an image instead of the selector, then call the block.
Upvotes: -1
Reputation: 38162
The reason for this warning is that with ARC, the runtime needs to know what to do with the result of the method you're calling. The result could be anything: void, int, char, NSString *, id, etc. ARC normally gets this information from the header of the object type you're working with.3
There are really only 4 things that ARC would consider for the return value:4
ns_returns_retained
)ns_returns_autoreleased
)This thread explains it in length.
Upvotes: 1
Reputation: 10160
The warning is there for a reason. You can check if mainImage responds to selector before performing it. The warning will not go away, but it is more safe. Something like this:
SEL _selector = NSSelectorFromString(@"asdf");
if([self respondsToSelector:_selector])
[self performSelector:_selector];
Upvotes: 2