据我了解,现在设置 ivar 会保留分配给它的对象,因为设置变量默认为 strong
限定符。因为 ivars 在声明它们的对象的范围内,而 strong
将对象保留在变量的范围内,这意味着当包含 ivar 的对象仍然存在时,永远不会释放 ivars 值。
这对吗?
如果是这样,我是否认为在内存管理方面,保留(强)属性和简单 ivar 之间不再有区别?
最佳答案
如果是变量:
然后将其声明为没有相应 @property
/@synthesize
的 ivar 并在实现中直接引用它是合适的。它与 Encapsulation 内联在类实现文件中声明这个 ivar。
// MyClass.h
@interface MyClass : ParentClass
@end
// MyClass.m
@implementation MyClass {
NSString *myString;
}
- (void)myMethod {
myString = @"I'm setting my ivar directly";
}
@end
__strong
。 nil
,如果是原语则初始化为0
。https://stackoverflow.com/questions/7836182/
相关文章:
ios - 根据文本量更改 UITableViewCell 高度
ios - UICollectionView:如何检测滚动何时停止
objective-c - UIScrollView contentSize 不起作用
ios - performFetchWithCompletionHandler 永远不会被解雇
ios - iOS 10 中的错误 : Unable to copy asset informati
iphone - 如何使用 NSLog(@"Inside of the iPhone Simulat