Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSFileManager泄漏_Iphone_Cocoa Touch_Cocoa_Memory Management_Nsfilemanager - Fatal编程技术网

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的泄漏模板,特别是对象历史记录功能,查看泄漏的内容和方式。