我使用此代码从文件加载一组属性,然后对其进行赋值。
NSMutableData* data = [NSData dataWithContentsOfFile:fullPath];
NSKeyedUnarchiver* unarc = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSMutableArray* loadedLibraries = [unarc decodeObjectForKey:@"libraries"];
IRStudyPlan* loadedStudyPlan = [unarc decodeObjectForKey:@"currentStudyPlan"];
NSMutableDictionary* loadedWordLists = [unarc decodeObjectForKey:@"wordLists"];
NSMutableDictionary* loadedStudyPlanList = [unarc decodeObjectForKey:@"studyPlanList"];
[unarc finishDecoding];
[self setLibraries:loadedLibraries];
[self setStudyPlanList:loadedStudyPlanList];
[self setCurrentStudyPlan:loadedStudyPlan];
[self setWordLists:loadedWordLists];
[unarc release];我想知道为什么在每个对象上都有内存泄漏。我的initWithCoder是这样的,所有对象都是这样的:
-(id)initWithCoder:(NSCoder *)decoder{
if([super init]!=nil){
[self setListName:[decoder decodeObjectForKey:@"listName"]];
[self setWordsWithStatistics:[decoder decodeObjectForKey:@"wordsWithStatistics"]];
[self setWordsWithStatisticsInGame:[decoder decodeObjectForKey:@"wordsWithStatisticsInGame"]];
}
return self;}
有谁能开导我吗?
非常感谢
发布于 2011-07-27 06:21:54
仪器将显示泄漏的内存分配的位置,在您的情况下,从NSKeyedUnarchiver。最有可能的是,您正在泄漏包含此代码的对象。看看这段代码所来自的对象的生命周期。
https://stackoverflow.com/questions/5573902
复制相似问题