【发布时间】:2011-07-25 04:15:49
【问题描述】:
在“checkFiles”方法中,我只是搜索了一个 NSDocumentDirectory 路径并请求了文件列表。
- (void) checkFiles{
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [pathList objectAtIndex:0];
NSArray *dirArray = [myFileManager contentsOfDirectoryAtPath:path error:NULL]; // leak occurs here!
/* .... */
}
-
-
Leaks Instruments 检测 NSFileManager 的 contentsOfDirectoryAtPath 方法的泄漏。
这是我在 Instruments 中单击一个名为 NSCFString 的泄漏对象时的堆栈跟踪。
0 CoreFoundation __CFAllocatorSystemAllocate
1 CoreFoundation CFAllocatorAllocate
2 CoreFoundation _CFRuntimeCreateInstance
3 CoreFoundation __CFStringCreateImmutableFunnel3
4 CoreFoundation CFStringCreateWithBytes
5 Foundation -[NSFileManager directoryContentsAtPath:matchingExtension:options:keepExtension:error:]
6 Foundation -[NSFileManager contentsOfDirectoryAtPath:error:]
因为我经常调用“checkFiles”方法来更新包含文件列表的 UITableView,所以我无法避免这种泄漏。
我应该如何修复这种系统泄漏?
谢谢。
【问题讨论】:
标签: iphone objective-c memory memory-leaks