2011-04-06 145 views
2

我有这段代码从文件中加载一组属性,然后分配它。NSKeyedUnarchiver内存泄漏

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; 

}

任何人都可以告诉我吗?

非常感谢您

回答

3

仪器将展示泄漏的内存被分配,你的情况从NSKeyedUnarchiver。最有可能的是,您正在泄漏包含此代码的对象。查看此代码来自的对象的生命周期。