Iphone NSFileManager泄漏
我在下面编写的代码片段中发现了内存泄漏Iphone NSFileManager泄漏,iphone,cocoa-touch,cocoa,memory-management,nsfilemanager,Iphone,Cocoa Touch,Cocoa,Memory Management,Nsfilemanager,我在下面编写的代码片段中发现了内存泄漏 NSFileManager *fileManager=[[NSFileManager alloc] init]; fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS_FOLDER error:nil] retain]; [fileManager release]; 泄漏信息- [NSFileManager contentsOfDirectoryAtPath:error:] [NSFil
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.
我不知道如何解决这个问题?您的alloc然后发布文件管理器就可以了。但是
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS\u文件夹错误:nil]retain]代码>
现在您有了一个保留的数组。你必须稍后发布它。如果您不这样做,您将有一个漏洞。您的alloc然后释放文件管理器就可以了。但是
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS\u文件夹错误:nil]retain]代码>
现在您有了一个保留的数组。你必须稍后发布它。如果不这样做,就会出现漏洞。内存管理的经验法则很简单:
对于每个分配
、保留
、复制
、或新建
,您必须有相应的发布
或自动释放
你在这里打电话:
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS_FOLDER error:nil] retain];
但您不会释放它。内存管理的经验法则很简单:
对于每个分配
、保留
、复制
、或新建
,您必须有相应的发布
或自动释放
你在这里打电话:
fileList=[[fileManager contentsOfDirectoryAtPath:DOCUMENTS_FOLDER error:nil] retain];
但是您没有释放它。您是否稍后释放fileList
文件?您是否稍后释放fileList
文件?如果覆盖此代码,如:fileList=[fileManager contents sofdirecorryatpath:DOCUMENT\u FOLDER error:nil];它也漏水!怎么做?@scofield:同样的方法。您必须保留或复制它以后,然后未能释放它。使用Instruments的泄漏模板(尤其是对象历史记录功能)查看泄漏的内容和方式。如果覆盖此代码,如:fileList=[fileManager contentsOfDirecotryAtPath:DOCUMENT_FOLDER error:nil];它也漏水!怎么做?@scofield:同样的方法。您必须保留或复制它以后,然后未能释放它。使用Instruments的泄漏模板,特别是对象历史记录功能,查看泄漏的内容和方式。