使用ARC时释放NSMutableArray [英] Release a NSMutableArray when using ARC

查看:94
本文介绍了使用ARC时释放NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的SDK和ARC开发iOS应用程序.

我有这个变量:

NSMutableArray* _previewImageBuffer;

这种方法:

- (void)shutdown
{
    [self stop];
    _previewImageBuffer = nil;
}

_previewImageBuffer = nil;是否正确?如果我这样做了,在_previewImageBuffer`中分配的内存会怎样?这是内存泄漏吗?

我想释放该对象,因为我需要释放它使用的内存.

解决方案

您所做的完全正确.取消ARC下的对象实例变量将释放该对象.释放NSArray(如果它导致NSArray被释放),还将释放其所有元素.

如果您对内存管理和ARC存有疑问或困惑,那么最好停止并仔细阅读事实,直到不再有疑问或困惑为止.我的书有一个可能有用的解释:

http://www.apeth.com/iOSBook/ch12.html#_memory_management

I'm developing an iOS application using latest SDK and ARC.

I have this variable:

NSMutableArray* _previewImageBuffer;

And this method:

- (void)shutdown
{
    [self stop];
    _previewImageBuffer = nil;
}

Is _previewImageBuffer = nil; correct? If I do it, what happens with memory allocated in _previewImageBuffer`? Is this a memory leak?

I want to release this object because I need to release the memory used by it.

解决方案

What you're doing is exactly right. Nilifying an object instance variable under ARC releases the object. Releasing an NSArray, if it causes the NSArray to be deallocated, also releases all its elements.

If you're in doubt or confused about memory management and ARC, you might do well to stop and read up on the facts until you're no longer in doubt or confused. My book has a possibly helpful explanation:

http://www.apeth.com/iOSBook/ch12.html#_memory_management

这篇关于使用ARC时释放NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆