我正在整理我的 iPhone 应用程序的一些内存问题,并且我一直在考虑一些基础知识。如果我设置了一个 ivar 并且在对象的生命周期内从未使用过它,那么当我在其上调用 dealloc 时,会导致问题吗?例如
@interface testClass {
id myobject;
}
@property (nonatomic, retain) id myobject;
@end
@implementation testClass
@synthesize myobject;
- (id)init {
...
// Do I have to set myobject to nil here?
// So if myobject isn't used the dealloc call to nil
// will be okay? Or can you release the variable without
// having set every object to nil that you may may not use
...
}
...
// Somewhere in the code, myobject may be set to
// an instance of an object via self.myobject = [AnObject grabAnObject]
// but the object may be left alone
...
- (void)dealloc {
[myobject release];
[super dealloc];
}
@end
最佳答案
实例变量are initialized to 0在初始化程序运行之前..
关于iphone - Objective-C 中的实例变量是否默认设置为 nil?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1786781/