即使我们不拥有ivar的(alloc/new/copy),我们是否必须在dealloc中释放ivar?即使我们不拥有伊娃的(alloc/new/copy),我们是否必须在dealloc中释放伊娃?
例如,这是正确的吗?
-(void)dealloc {
[_aUIImageIvar release];
[super dealloc];
}
-(id)init{
self = [super init];
if (self) {
_aUIImageIvar = [UIImage imageWithData:data];
}
}
不可以。不要释放你不拥有的东西。但为什么你不保留这个形象? – rmaddy
谢谢@rmaddy,我忘了保留它...因为我没有使用setter,所以很容易忘记保留。 – Cong
简单的规则,如保留 - 释放配对容易与其他事物混淆... – Cong