开发者

EXC_BAD_ACCESS - iPhone

My iPhone app is crashing and getting EXC_BAD_ACCESS error when using this code:

NSError *error;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
        NSString *documentsDirectory = [paths objectAtIndex:0]; //2
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"stats.plist"]; //3

        NSFileManager *fileManager = [NSFileManager defaultManager];

        if (![fileManager fileExistsAtPath: path]) //4
        {
            NSString *bundle = [[NSBundle mainBundle] pathForResource:@"stats" ofType:@"plist"]; //5

            [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
            [bundle release];
        }

        NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

        //load from savedStock example int value
        score.highScore = [[savedStock objectForKey:@"score"] intValue];
        score.deaths = [[savedStock objectForKey:@"deaths"] intValue];
        score.iFallPoints = [[savedStock objectForKey:@"iFallPoints"] intValue];
        score.difficulty = [[savedStock object开发者_如何学编程ForKey:@"difficulty"] intValue];

        [savedStock release];

score is the singleton I am accessing.


You didn't alloc or retain bundle; don't release it.

See the memory management programming guide if you need help understanding it.

Also, the static analyzer can be helpful for pointing some out memory bugs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜