views:

98

answers:

3

Hello all ,

I am working on iPhone application..

For the purpose of finding memory leaks I have started the application with the instruments which gave me lots of leaks . which i was unable to understand then in a forum somewhere I have read that the instruments gives spurious leaks sometime so I should start by the Static analysis .

Then I have used Clang Static analyser and it gave me only 7 bugs after solving that my app was bug free from the view of Static analysis .

Both analysis leaks were different .

If I still test with instruments it still gives leaks .

So my question is that should I rely on the clang Static Analyzer results or Instruments results ..

+4  A: 

They're complimentary tools that spot problems in your code in two very different ways. You should use both.

Stephen Darlington
So If one is saying bug free and the other one says "you still have bugs" which one to accept or both ?
hib
Clang is not saying your code is bug-free. It's saying it only sees seven bugs. As Stephen said, both spot different problems. If one sees a problem, you should trust it.
Chuck
ok thanks Chuck ...
hib
Actually, if you see a problem, you should *not* trust it, but investigate it. Both Instruments and the Clang static analyzer are known to return false positives, depending on the "bug" and whether the application is being run on the Simulator or device.
Alex Reynolds
Yes, that's a better way of putting it. I meant to say you shouldn't discount it just because something else failed to find the bug.
Chuck
+1  A: 

CLANG saying "no results" doesn't mean you are bug free. It means that "CLANG" has found all the problems it can find. Just like the leaks tool cannot find all problems you consider to be leaks, because there are some things it cannot detect, and it only can find issues in the area of the app you actually tested while running it...

Think of the overall state of bugs in your application as an elephant, and the various debugging tools in XCode as a stable of blind men to try and grasp the shape of it. With enough blind men thrown at an elephant you eventually will approximate the shape of any problem you have. That's why you have to use all the tools possible.

For extra CLAG scrubbing power, set the compiler type to CLANG/LLVM. You can only compile for the simulator with that setting, but when used in conjunction with the static analyzer it can find more issues.

Kendall Helmstetter Gelner
how to do this "For extra CLAG scrubbing power, set the compiler type to CLANG/LLVM" ?
hib
Open up project settingsSelect the Build tab.Scroll down to "C/C++ Compiler Version". Change the dropdown to "CLANG LLVM 1.0". Don't forget to unset it before you compile for the device. I usually make a separate Debug configuration with this enabled to run it quickly.
Kendall Helmstetter Gelner
+1  A: 

You shouldn't rely on one or the other, they both do very different things. Use clang to spot potential problems before you test, then use instruments to test.

Also, make sure to you instruments with both the simulator and the device. If you follow memory management best practices you'll rarely have a leak, but clang and instruments are valuable tools in tracking down leaks that might creep in.

jessecurry