我是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)