相关疑难解决方法(0)

如何在xcode中使用NSzombie?

可能重复:
如何在Xcode 4上启用NSZombie?

我的应用程序崩溃了很多!如何通过NSZombie找到错误?

有人可以给我一步一步的指示,使用NSZombie或Valgrind工具来查找内存错误,引用错误等.

iphone xcode memory-management objective-c nszombie

9
推荐指数
0
解决办法
2万
查看次数

为什么不崩溃?

我试图将一个bug缩小到最小可重复的情况并发现一些奇怪的东西.

考虑以下代码:

static NSString *staticString = nil;
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    if (staticString == nil) {
        staticString = [[NSArray arrayWithObjects:@"1", @"2", @"3", nil] componentsJoinedByString:@","];
    }   

    [pool drain];

    NSLog(@"static: %@", staticString);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

期待这段代码崩溃.相反,它记录:

2011-01-18 14:41:06.311 EmptyFoundation[61419:a0f] static: static: 
Run Code Online (Sandbox Code Playgroud)

但是,如果我NSLog()改为:

NSLog(@"static: %s", [staticString UTF8String]);
Run Code Online (Sandbox Code Playgroud)

然后,它不会崩溃.

编辑更多信息:

排水后:

NSLog(@"static: %@", staticString);  //this logs "static: static: "
NSLog(@"static: %@", [staticString description]); //this crashes …
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c autorelease

9
推荐指数
2
解决办法
1230
查看次数