我在以下我编写的代码片段中发现了内存泄漏
NSFileManager *fileManager=[[NSFileManager alloc] init];
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS_FOLDER error:nil] retain];
[fileManager release]; 泄露信息-
[NSFileManager contentsOfDirectoryAtPath:error:]
[NSFileManager directoryContentsAtPath:matchingExtension:options:keepExtension:error]
CFStringCreateWithBytes
_CFStringCreateImmutableFunnel3
_CFRuntimeCreateInstance.我不知道该怎么解决?
发布于 2011-06-20 12:09:00
您的文件管理器的alloc-then-release很好。但
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS_FOLDER error:nil] retain];
现在,您拥有了一个保留的数组。您必须稍后发布它。如果你不这样做,你将会有一个漏洞。
发布于 2011-06-20 12:11:59
内存管理的经验法则很简单:
对于每个alloc、retain、copy或new,都必须有相应的release或autorelease。
您将在此处调用retain:
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS_FOLDER error:nil] retain];但你不会释放它。
https://stackoverflow.com/questions/6406681
复制相似问题