[英]Why do I have to clean up memory if I have an IBOutlet with “retain”, but not when I have one with “assign”?
Example: 例:
@property (..., assign)
there, I don't do any cleanup in the dealloc Method. 在那里,我没有在dealloc方法中进行任何清理。 But when I have an 但是当我有一个
@property (..., retain)
then I would do so. 那么我会这样做。
I have that from somewhere in the internet. 我在互联网上的某个地方有那个。 Don't remember the site. 不记得该网站了。 Well, I know that the retain-keyword in the compiler directive would make a retain count +1, but actually I think that I missed the deep difference in assign and retain. 好吧,我知道编译器指令中的retain-keyword会使retain count +1,但实际上我认为我错过了assign和retain的深层区别。
Assign will only copy the pointer, and don't send a retain
message to the object. Assign将仅复制指针,而不向对象发送retain
消息。 Thus, since you are not retaining it, you don't have to release it. 因此,由于您没有保留它,因此不必释放它。
In case of retain, as you say, it will send a retain
message to the object, incrementing its retain count, so you are responsible of sending that object a release
message when your object is (in your dealloc
). 如您所说,在保留的情况下,它将向对象发送retain
消息,从而增加其保留计数,因此您有责任在对象(在dealloc
)发送该对象的release
消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.