小编Jon*_*han的帖子

NSMutableArray initWithContentsOfFile内存泄漏

我是iPhone开发的新手,我有这个内存泄漏.

我使用NSMutableArray来检索位于Documents目录中的.plist文件的内容.

我第一次使用它,一切都很顺利,但如果我多次调用它,我会得到内存泄漏.

这是我的代码:

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  NSArray *paths = NSSearchPathForDirectoriesInDomains
                       (NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
     //make a file name to write the data to using the
     //documents directory:
  fullFileName = [NSString stringWithFormat:@"%@/SavedArray", documentsDirectory];
     //retrieve your array by using initWithContentsOfFile while passing
     //the name of the file where you saved the array contents.
  savedArray = nil;
  savedArray = [[NSMutableArray alloc] initWithContentsOfFile:fullFileName];
  self.composedArray = [savedArray copy];
  [savedArray release];
  [self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)

每次视图消失时我都会释放它

- (void)viewWillDisappear:(BOOL)animated {
  [super …
Run Code Online (Sandbox Code Playgroud)

memory cocoa memory-leaks nsmutablearray

2
推荐指数
1
解决办法
2472
查看次数

标签 统计

cocoa ×1

memory ×1

memory-leaks ×1

nsmutablearray ×1