Ios 自动参考计数&;综合性能

Ios 自动参考计数&;综合性能,ios,cocoa-touch,memory-management,automatic-ref-counting,Ios,Cocoa Touch,Memory Management,Automatic Ref Counting,在使用ARC for iOS时,以下各项之间是否有任何区别 @property (strong, nonatomic) NSObject *someProperty; ... @synthesize someProperty; //and then in the init method, either: self.someProperty = aProperty; //or someProperty = aProperty; 我知道在没有ARC的情况下,self.someProperty实

在使用ARC for iOS时,以下各项之间是否有任何区别

@property (strong, nonatomic) NSObject *someProperty;
...
@synthesize someProperty;

//and then in the init method, either:
self.someProperty = aProperty;

//or
someProperty = aProperty;
我知道在没有ARC的情况下,self.someProperty实际上正在调用合成setter方法,该方法向对象发送
retain
消息。但是现在对于弧,如果我使用点符号来设置这样的属性,有关系吗


更一般地说,ARC真的意味着我根本不必担心引用计数吗?或者在某些情况下,我编写代码的方式可能会导致ARC出错

区别与没有ARC的情况相同:通过使用点表示法,您正在调用合成setter,通过直接分配给ivar,您正在使用setter方法

在ARC下,这两个选项之间的内存管理没有区别,但您仍然应该在这两个选项之间做出有意识的决定:例如,直接分配给ivar会绕过KVO,而使用setter方法稍微慢一点,但在大多数情况下可能更安全,例如,当您以后决定将属性设置为原子属性或覆盖setter时


就个人而言,我总是使用属性表示法
self.abc=
除了在
init
中可能需要绕过KVO之外。简而言之,使用与ARC之前相同的推理。

访问器方法的另一个更微妙的好处是,您可以在它们上设置断点,以查看何时发生了更改。