0

我有一个为 iOS 4.x 编写的项目。最近我使用 XCode 4.3.2 将它更新到 iOS5。奇怪的是,在使用 Apple LLVM 编译器时,应用程序每次都停止并出现双重释放错误。在我改回 LLVM GCC 后,它工作正常。这两者有什么区别吗?代码如下所示:

- (NSArray *)readCourselist {

    NSString *path = [[self currentUserPathString] stringByAppendingPathComponent:kUserCourseListFilename];

    return [NSArray arrayWithContentsOfFile:path];

}

- (NSArray *)getCourselist {

    NSArray *courseRawArray = [self readCourselist];

    for (NSDictionary *courseDic in courseRawArray) {

        CourseModel *courseModel = [[CourseModel alloc] init];

        courseModel.courseID = [[courseDic objectForKey:kKeyID] intValue];

        courseModel.courseNameString = [courseDic objectForKey:kKeyTitle];

        NSArray *lectureArray = [courseDic objectForKey:kKeyLecture];

        for (NSDictionary *lectureDic in lectureArray) {

            LectureModel *lectureModel = [[LectureModel alloc] init];

            NSString *startString = [lectureDic objectForKey:kKeyStart];


            if ([startString isEqualToString:@"8:00"]) {

                lectureModel.lectureNumber = 1;

            }

            else if ([startString isEqualToString:@"9:50"]) {

                lectureModel.lectureNumber = 2;

            }



            lectureModel.location = [lectureDic objectForKey:kKeyWhere];  //@property of location is retain

            [courseModel.lectureArray addObject:lectureModel];

            [lectureModel release];

        }

        [courseArray addObject:courseModel];

        [courseModel release];

    }

}

随着更多的追踪,我发现它是

lectureModel.location = [lectureDic objectForKey:kKeyWhere];

这真的很重要。在我的 LectureModel 中,位置声明如下

@property (nonatomic, retain) NSString *location;

@synthesize location;

- (id)init {
    location = NSLocalizedString(@"未知", nil);
}

删除 NSLocalizedString 一切正常。为什么?

4

1 回答 1

0

通常与NSDictionary您一起工作时要使用valueForKey:而不是objectForKey:,但我认为这不是问题所在。如果您将其转回 LLVM,并使用“Zombies”运行 Instruments,它应该会指出每个免费(嗯,发布)发生的确切位置。

于 2012-04-12T14:22:38.213 回答