我在我的 h 文件中创建了多个实例
IBOutlet UIImageView *imageView; IBOutlet UIImageView *subImageView;
IBOutlet UIImageView *arrowRight;
IBOutlet UIImageView *arrowLeft;
IBOutlet UIImageView *arrowDown;
我的项目处于 ARC 模式
我必须在 dealloc () 方法中将它们设置为 nil 才能释放它们吗?
谢谢
我在我的 h 文件中创建了多个实例
IBOutlet UIImageView *imageView; IBOutlet UIImageView *subImageView;
IBOutlet UIImageView *arrowRight;
IBOutlet UIImageView *arrowLeft;
IBOutlet UIImageView *arrowDown;
我的项目处于 ARC 模式
我必须在 dealloc () 方法中将它们设置为 nil 才能释放它们吗?
谢谢
如果在释放对象之一后不需要全局实例,最好的方法是将全局指针设置为nilin dealloc。
- (void)dealloc {
gYourGlobalPointer = nil;
}
请注意,在 ARC 中您不能调用[super dealloc], dealloc 将自动发送到您的超类。
您可以将它们设为 nil, viewDidUnload如下所示:
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.myOutlet = nil;
}
在 ARC 中,您根本不必担心释放属性的实例名副其实。编译器将为您处理它们。
如果要手动释放,则必须将 nil 分配给指向特定实例的所有强变量。