分析是顯示內存泄漏其中I在下面的代碼段分配文件路徑值FILEB:內存泄漏:
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docsDir stringByAppendingPathComponent:@"/fileA"];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
self.propertyA = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
} else {
// initialize array with default values and write to data file fileA
[self populatePropertyAForFile:filePath];
}
filePath = [docsDir stringByAppendingPathComponent:@"/fileB"];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
self.propertyB = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
} else {
// initialize array with default values and write to data file fileB
[self populatePropertyBForFile:filePath];
}
我明白這是因爲(爲的fileA)的前一個值還沒有被釋放。但我無法弄清楚如何阻止這種泄漏。
有些事情你不告訴我們。 – 2012-07-05 15:37:13