does setting an object to nil with ARC cause a rel

2019-08-28 14:48发布

问题:

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.