iPhone内存管理问题和对象生命周期

iPhone内存管理问题和对象生命周期,iphone,objective-c,cocoa,memory-management,Iphone,Objective C,Cocoa,Memory Management,以下是我的代码: Phone SDK未识别的cocoa对象活动周期: - (void) DismissWelcomeMessage: (UIAlertView *) view { [view dismissWithClickedButtonIndex:0 animated:YES]; } - (void) ShowWelcomeMessage { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Blah" m

以下是我的代码:

Phone SDK未识别的cocoa对象活动周期:

- (void) DismissWelcomeMessage: (UIAlertView *) view
{
    [view dismissWithClickedButtonIndex:0 animated:YES];
}

- (void) ShowWelcomeMessage 
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Blah" message:@"Blah Blah" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [self performSelector:@selector (DismissWelcomeMessage:) withObject: alert  afterDelay: WELCOME_MESSAGE_DELAY]; 

    [alert release];
}
首先调用ShowWelcomeMessage

为什么DissmisswelcoMessage工作正常,即使释放警报对象也不会崩溃

是因为Disclease函数在调用函数时使用传递到堆栈上的对象的副本作为参数吗?但即使这样,它也只是指向现在解除分配的对象的指针的副本吗

或者[alert release]只是将引用计数递减,实际上与
在C++中删除.< /p> ,PrExpRealStor可能保留传入的对象,这就是为什么在调用DISM时,它仍然是有效的。

< P>可能PrPrExcStor保留传入的对象,这就是为什么在调用DISM时仍然有效的。

< P>格式选择器保留该对象,因此,您的发布不会导致其保留计数变为零


此方法将保留receiver和anArgument参数,直到执行选择器。

performSelector保留对象,因此您的释放不会导致其保留计数变为零

此方法保留receiver和anArgument参数,直到执行选择器