Reputation: 18237
I'm trying to write some generic http response handler functions that sometimes open UIAlertViews.
These generic handlers are class methods don't have knowledge of their callers (at the moment).
But I'm facing an obvious problem about how to alloc/dealloc the UiAlertView delegate object.
e.g.
MyAlertViewHandler* alertHandler = [[MyAlertViewHandler alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg message:nil delegate:alertHandler cancelButtonTitle:TEXT_NEVERMIND otherButtonTitles:TEXT_RESET_PASSWORD,nil];
[alert show];
[alert autorelease];
There's an obvious memory leak there cos I'm alloc'ing and not release it anywhere.
So, where do I "hang" MyAlertViewHandler such that I can release it to avoid the memory leak?
One idea is to tell the caller there's a NSObject that needs to be released and give responsibility back to the UIViewController - but is there another way?
I hope my question is clear enough.
Upvotes: 0
Views: 115
Reputation: 92335
In your alertView:didDismissWithButtonIndex:
delegate method (in your MyAlertViewHandler
) you could simply [self release];
or [self autorelease];
as the very last command.
Upvotes: 1