开发者

Objective C selector memory managment (does this leak memory)?

- (IBAction) someButtonCall {

        if(!someCondition) {
            someButtonCallBack = @selector(someButtonCall);
            [self presentModalViewController:someController animated:YES]; 
        } else
        ...
}

//Called from someController
- (void) someControllerFinished:(BOOL) ok {
   [self dismissModalViewControllerAnimated:YES];
   if(ok) [self performSelector:someButtonCallBack];
   else ...
}

I'm wondering if the user keeps getting into the !someCondition clause if the selector is leaked by assigning a new selector each time (the code above is hypothetical and not what i'm doing).

Any help is appreciated.

Thank开发者_StackOverflows, James Jones


No, this doesn't leak anything - you don't own the SEL values returned by @selector() and sel_registerName(), the Objective-C runtime does.


The SEL type is simply a C string, so you won't have memory leaks whit re-assignations.


This example does not leak memory. @selector() is evaluated at compile time. You could possibly leak a SEL variable, but not the selector itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜