【发布时间】:2012-07-05 15:31:43
【问题描述】:
Analyze 显示内存泄漏,我在以下代码 sn-p 中为 fileB 分配了 filePath 值:
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)尚未发布。但我不知道如何阻止这种泄漏。
【问题讨论】:
-
有些事情你没有告诉我们。
标签: objective-c ios