The analyzer is very good at finding the routine leaks that plague new programmers writing non-ARC code (failures to call release
, returning objects of the wrong retain count, etc.).
In my experience, there are a couple of types of memory issues it does not find:
It cannot generally identify strong reference cycles (a.k.a. retain cycles). For example, you add a repeating
NSTimer
to a view controller, unaware that the timer maintains a strong reference to the view controller, and if you don'tinvalidate
the timer (or do it in the wrong place, such as thedealloc
method), neither the view controller nor the timer will get released.It cannot find circular logic errors. For example, if you have some circular references where view controller A presents view controller B, which in turn presents a new copy of A (rather than dismissing/popping to get back to A).
It cannot find many non-reference counting memory issues. While it's getting better in dealing with Core Foundation functions, if you have code that is doing manual memory allocations (such as via
malloc
andfree
), the static analyzer may be of limited use. The same is true whenever you're using non-reference counting code (e.g. you use SQLitesqlite3_prepare_v2
and fail to callsqlite3_finalize
).
I'm sure that's not a complete list of what it doesn't find, but those are the common issues I see asked about on Stack Overflow for which the static analyzer will be of limited help. But the analyzer is still a wonderful tool (it finds issues other than memory issues, too) and for those individuals not using ARC, it's invaluable.
Having said that, while the static analyzer is an under-appreciated first line of defense, you really should use Instruments to find leaks. See Locating Memory Issues in Your App in the Instruments User Guide. That's the best way to identify leaks.