UIAlertView* av = [UIAlertView alloc];
int a = [self somefunc];
if (a == 1)
{
[[av initWithTitle:nil message:@"test msg 1" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
else if (a == 2)
{
[[av initWithTitle:nil message:@"test msg 2" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
[av release];
当我在此代码上运行分析时,我在行收到错误“引用计数的对象在它被释放后被使用”[av release];
我能知道,在哪里发布了 av,UIAlertView 的显示功能是否发布了 av?
奇怪的是,下面的代码在使用分析工具时没有显示任何错误
if (a == 1)
{
UIAlertView* av = [[UIAlertView alloc] initWithTitle:nil message:@"test msg 1" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
[av release];
}
else if (a == 2)
{
UIAlertView* av = [[UIAlertView alloc] initWithTitle:nil message:@"test msg 1" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
[av release];
}