does setting an object to nil with ARC cause a release of its properties

删除回忆录丶 提交于 2019-12-11 18:24:33

问题


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?


回答1:


You should read this Apple Memory Management documentation.

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.

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.



来源:https://stackoverflow.com/questions/16581040/does-setting-an-object-to-nil-with-arc-cause-a-release-of-its-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!