I have a project written for iOS 4.x. Recently i update it to iOS5 using XCode 4.3.2. It's strange that the app stop everytime with double free error when using Apple LLVM compiler. After i change back to LLVM GCC, it works fine. 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
@property (nonatomic, retain) NSString *location;
@synthesize location;
- (id)init {
location = NSLocalizedString(@"未知", nil);
}
Delete NSLocalizedString and everything works all right. Why?