Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

performSelector:withObject: and its retain behavior

This is an already answer question within SO but I cannot find it in the Apple documentation anywhere. Could you point me in the right direction?

Within the following topics

Do I have to retain an object before passing it to -performSelector:withObject:afterDelay:?

the effect on retain count of performSelector:withObject:afterDelay:inModes

Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop?

the default behaviour seems to be the following: it retains the receiver and the argument(s).

I'm using the following code

[[self delegate] performSelector:@selector(tryToSendStoreData:) withObject:userData];

where userData is an autoreleased oject.

Logging the retain count (I know that it could be not valid to do it) the data passed in increments its retain count. When the method is invoked on the delegate, the retain count is not equal to one.

So, my question is: do I need to perform some memory management to avoid leaks or do I have to trust on Apple stuff? Here I'm speaking as an agnostic since I cannot find the right docs.

Thank you in advance.

like image 437
Lorenzo B Avatar asked Jun 27 '12 14:06

Lorenzo B


1 Answers

You are looking at the wrong function in the documentation.

Retain

performSelector:withObject:afterDelay: and similar functions (with afterDelay) retain the receiver and arguments, because the execute later

No Retain

performSelector:withObject: and similar functions (without afterDelay) do not retain anything, since they just call the function directly.

[[self delegate] performSelector:@selector(tryToSendStoreData:) withObject:userData];

does the exact same thing as

[[self delegate] tryToSendStoreData:userData];
like image 136
newacct Avatar answered Nov 09 '22 13:11

newacct