[英]Double free error when using Apple LLVM compiler
I have a project written for iOS 4.x. 我有一个专为iOS 4.x编写的项目。 Recently i update it to iOS5 using XCode 4.3.2.
最近,我使用XCode 4.3.2将其更新到iOS5。 It's strange that the app stop everytime with double free error when using Apple LLVM compiler.
奇怪的是,使用Apple LLVM编译器时,应用程序每次都会停止,并出现两次免费错误。 After i change back to LLVM GCC, it works fine.
我改回LLVM GCC之后,它可以正常工作。 Is there any difference between this two?
两者之间有什么区别吗? The code is shown below:
代码如下所示:
- (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];
}
}
With more tracing i found out that it's 通过更多的追踪,我发现它是
lectureModel.location = [lectureDic objectForKey:kKeyWhere];
that really matters. 真的很重要。 In my LectureModel, location is declared as follow
在我的LectureModel中,位置声明如下
@property (nonatomic, retain) NSString *location;
@synthesize location;
- (id)init {
location = NSLocalizedString(@"未知", nil);
}
Delete NSLocalizedString and everything works all right. 删除NSLocalizedString,一切正常。 Why?
为什么?
Generally working with NSDictionary
you want to use valueForKey:
instead of objectForKey:
, but I don't think that's the problem here. 通常,与
NSDictionary
一起使用时,您想使用valueForKey:
而不是objectForKey:
但是我不认为这是问题所在。 If you flip it back to LLVM, and run Instruments with "Zombies", it should point you to exactly where each free (well, release) is occurring. 如果将其翻转回LLVM,并使用“ Zombies”运行Instruments,它应该指出每个释放(以及释放)的确切位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.