2011-04-06 144 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。最有可能的是,您正在泄漏包含此代碼的對象。查看此代碼來自的對象的生命週期。