在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
对象、变量、变量修饰符、赋值
1、站在对象和引用计数的角度看:我不关心谁拥有我,我只关心谁想我发出了维护消息; [_dog release]; 2、任何变量的赋值,都代表了内存规则的进一步维护;
引用计数的语义是什么? 指针,内存变量、对象
strong、retain、release:向对象发送消息,修改引用计数的值; 赋值操作:使用变量修饰符对内存维护机制发送维护信息;
Variable Qualifiers You use the following lifetime qualifiers for variables just like you would, say, const.
https://developer.apple.com/library/archive/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
You don't have to explicitly specify __autoreleasing when defining a function that returns an object, for example -(BOOL)doSomething:(NSError **)error; The ARC compiler automatically inserts the __autoreleasing. This is explained in the Clang/ARC documentation: 4.4.2 Indirect parameters If a function or method parameter has type T*, where T is an ownership-unqualified retainable object pointer type, then:
The Xcode code completion also knows about that and displays (NSError *__autoreleasing *)error.
When calling such a function the ARC compiler also automatically does "the right thing", so you can just call NSError *error; BOOL success = [self doSomething:&error]; As explained in the "Transitioning to ARC Release Notes", the compiler inserts a temporary __autoreleasing variable: NSError *error; NSError * __autoreleasing tmp = error; BOOL success = [self doSomething:&tmp]; error = tmp; (For the gory details you can read 4.3.4 "Passing to an out parameter by writeback" in the Clang/ARC documentation.)
https://stackoverflow.com/questions/23268576/autoreleasing-in-errornserror-autoreleasing-outerror
|
请发表评论