我有一个为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,一切正常。 为什么呢?
答案 0 :(得分:0)
通常使用NSDictionary
,您希望使用valueForKey:
代替objectForKey:
,但我不认为这是问题所在。如果你将它翻转回LLVM,并使用“Zombies”运行Instruments,它应该指向每个free(well,release)正在发生的确切位置。