How to release a "PopUp" view"?

Posted by david on Stack Overflow See other posts from Stack Overflow or by david
Published on 2010-05-15T08:26:59Z Indexed on 2010/05/15 8:34 UTC
Read the original article Hit count: 331

I have this class that shows a popup. I do a alloc-init on it and it comes up.

DarkVader* darkPopUp = [[DarkVader alloc] init:theButton helpMessage:[theButton.titleLabel.text intValue] isADay:NO offset:0];

It shows itself and if the user presses Ok it disappears. When do I release this?

I could do a [self release] in the class when the OK button is pressed. Is this correct? If I do this the Analyzer says it has a retain count of +1 and gets leaked in the calling function. If I release it just after the alloc-init the Analyzer says it has a retain count of +0 and i should not release it.

    DLog(@"DarkVader retain count: %i", [darkPopUp retainCount]);

says it has a retain count of 2. I'm confused.

In short my question is: How do I release an object that gets initialized does some work and ends but no one is there to release it in the calling function.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c