确实使用ARC将对象设置为nil会导致其属性的释放 [英] does setting an object to nil with ARC cause a release of its properties

查看:92
本文介绍了确实使用ARC将对象设置为nil会导致其属性的释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将一个对象(例如,一个视图控制器)设置为nil,它的属性(如按钮和标签)也会在ARC下释放吗?如果属性为强类型并分配,会发生什么情况?另外,当不使用ARC时,在我的delloc方法中,是否只释放保留类型属性?

If I set an object, say a view controller to nil, will its properties like buttons and labels also get released under ARC? What happens in case the properties are of type strong and assign? Also, when not using ARC, in my delloc method, do I only release retain type properties?

推荐答案

您应该阅读基本上,这取决于.除非其他实例保留了该视图控制器,否则它将被释放.然后,当它被释放时,它的属性将被释放-除非其他实例保留了它们.

Basically, it depends. The view controller would be released unless some other instance was retaining it. Then, when it is released, its properties would be released - unless some other instance was retaining them.

如果将这些属性引用的对象传递给另一个实例,或者(如果属性是某种UIView)将其他对象添加为子视图(然后将它们添加到的视图),则其他实例可能会保留这些引用.将保留它们.)

Other instance could be retaining these references if you pass the objects referenced by those properties to another instance, or (if the property is some kind of UIView) you add them as a subview (then the view you add them to will retain them).

重要的是,如果您是所有者,则释放参考,如果需要通过,则保留并在完成后释放.

The important thing is that if you're the owner you release the reference and if you need something you're passed, retain it and release it when you're done.

这篇关于确实使用ARC将对象设置为nil会导致其属性的释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆