views:

78

answers:

3

Hi guys, I'm new to iphone and objective-c development and want to ask if Clang Static Analyzer is enough for getting rid of memory leaks? I personally found the xcode "Leaks" tool rather difficult to use, besides I've seen some articles, where it reads that it will always show memory leaks, even if there are no any real leaks.

If I don't have any warnings from clang analyzer, does it mean that I don't have any memory leaks? Or I need to check it somehow else?

What do you think? Thank you very much.

+3  A: 

No it is not. CSA is a static analysis tool, meaning it can only catch things that can be reasoned about at compile time. To that end it also isn't perfect, far from it. It is definitely no substitute for Instruments. CSA can however, help remind you of things in the rules, and other potential problems.

jer
Ok, thanks for your answer, are there any other tools I should know about?
Burjua
Yes, as I mentioned in my answer, "Instruments". It will attach itself to the running application and using whichever instruments you are testing with, i.e., "Leaks" provide you information about the running application with how its being used.
jer
The object allocations tool is also very useful to make check if the object reside in memory as long as you expected them to. E.g. open then close a tableViewController and check if the displayed object died.
Felix
Yeah there's a lot of little instruments that are wonderful. Check it out seriously.
jer
+1  A: 

No, the static analyser is one of the tools that is handy to have but you shouldn't rely solely on it.

Instruments and in particular the Leaks and Memory allocation tools are great ways to find leaks. The memory allocation tool can help you find leaks that leaks can't because it can show you the overall memory usage, if you notice it going up but never coming down after you finish a task you can start looking for a possible leak...

James Raybould
+2  A: 

If you are using the built in Build and Analyze, you can get better results by downloading the real scan-build and turning on all checks

http://www.loufranco.com/blog/files/scan-build-better-than-build-analyze.html

But, it's still not enough. You need to check for leaks using run-time analysis. If you keep to very simple alloc/retain/release rules, you might be able to get away with it (or so close, that the Leaks tool becomes much easier to deal with).

Lou Franco