Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release a NSMutableArray when using ARC

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.

like image 222
VansFannel Avatar asked Sep 02 '26 00:09

VansFannel


1 Answers

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

like image 148
matt Avatar answered Sep 03 '26 13:09

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!