指望int在Objective-C中始终初始化为0 是否安全?
更具体地说,当int新实例化具有ivars 的对象时,可以安全地假设其ivars的值为0吗?
我正在用我的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
// …Run Code Online (Sandbox Code Playgroud)