相关疑难解决方法(0)

Objective-C中的实例变量默认设置为nil吗?

我正在用我的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)

iphone cocoa cocoa-touch memory-management objective-c

38
推荐指数
2
解决办法
1万
查看次数

Objective-C中的int是否自动初始化为0?

我正在阅读Stephen G. Kochan撰写的一本名为"Objective-C编程"的书,第六版.它在第144页上有以下声明,这使我感到困惑:

作为基本C数据类型的局部变量没有默认初始值,因此在使用它们之前必须将它们设置为某个值.

然而,当我有以下代码时,它仍然有效,并显示0:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    int number;
    NSLog(@"%i", number);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

是不是int基本的C数据类型?

c int objective-c local-variables variable-initialization

0
推荐指数
1
解决办法
403
查看次数