I was/am planning on making a full post about this because I find it incredibly useful: Clang Static Analyzer.
It's a tool utilizing LLVM/Clang which automatically finds memory leaks and other possible bugs with your code. It generates a nice HTML report for where the error occurs and how it got there.
I have found sticking to a coding standard is the single best way to prevent memory leaks. For example, always autorelease or always do the init, set, release jig, etc. However, tools like the static analyzer may find bugs you were unaware of.
website:
http://clang.llvm.org/StaticAnalysis.html
quick tutorial on setting up for iPhone development:
http://www.rhonabwy.com/wp/2008/10/...clang-static-analyzer-with-an-iphone-project/
Sure.Can you tell me detail steps to install this on my machine.
Sure.
- Go to http://clang.llvm.org/StaticAnalysis.html
- Download checker-xxx.tar.bz2 in the bottom right (is currently checker-113.tar.bz2 for the October 20th build)
- Extract to some directory (I chose ~/Development/tools/clang)
- Open your project in XCode and set settings to Simulator and Debug
- Build and Run (this step may be optional)
- Quit XCode
- In your terminal, cd to your project directory
- rm -rf ./build (this step may be optional)
- rm -rf /tmp/scan* (this is where the HTML reports are stored, this step may be optional too)
- run "/location/of/unzipped/file/scan-build --view xcodebuild". For example, I run "~/Development/tools/clang/scan-build --view xcodebuild". --view tells the scan-build to automatically bring up the HTML report in the browser.
I had that until I switched the XCode project to Simulator instead of Device. This error is because the analyzer does not support ARM binaries.
Also, in Step 5, instead of Build and Run, do a Clean on the target and do NOT Build and Run.