Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impact of Automatic Reference Counting (ARC) on Memory Leaks

I am new to iOS 5 and ARC, so pardon my silly question.

If we use ARC in our project, does it mean that there wont be any memory leaks at all.

Is there a need to use Instruments for detecting memory leaks and NSZombies if we use ARC?

like image 209
meetpd Avatar asked Jan 21 '12 05:01

meetpd


1 Answers

ARC will help you eliminate certain types of leaks, because you won't forget to release or autorelease single objects. For example, this type of error becomes impossible:

myLabel.text = [[NSString alloc] initWithFormat:@"%d", 17];
// oops, just leaked that NSString!

However, ARC will not eliminate leaks caused by retain cycles. It's still up to you to eliminate retain cycles, either by using weak references or by manually breaking the cycles before they become leaked. For example, as we start to use blocks more, block/self retain cycles become much more common. The Transitioning to ARC Release Notes discuss how to avoid these cycles using weak references.

like image 127
rob mayoff Avatar answered Sep 24 '22 09:09

rob mayoff