views:

122

answers:

2

I'm trying to use XCode's Leaks utility to fix some memory leaks in my code. Is there a better and more understandable way to check for leaks with explanations that pinpoint the exact line and/or offer suggestions?

Another question, I'm using AVAudioRecorder in my code in one of my view controllers. Should I load the recorder in viewDidLoad or in viewWillAppear?

+2  A: 

If you're using Snow Leopard, have you tried using the static analyzer?

Jeff Kelley
How do I do that? (Is it in XCode --> Run with Performance Tool?)
Anthony Glyadchenko
Anthony: Build -> Build and Analyze, or Cmd-Shift-A.
Noah Witherspoon
Can't stress enough how awesome this tool is. I rely on it so much that if I run it and find no errors I create one just to see it reported for peace of mind.
Adam Eberbach
Did not know about the static analyzer in snow leopard's tools. Thanks.
Brandon Bodnár
A: 

As mentioned, use Static Analyzer as a first line of defense.

It will not find everything.

But here's the problem with what you are requesting of Leaks. Think about what a leak is - a leak is when you have memory, that should have been released, but it is not.

So that means you are MISSING a line of code, that could have been placed anywhere - doing the actual release at the right time. But how could the tool possibly know when something SHOULD have been released?

So instead, the tool does the next best thing. It tells you where the leaking memory was allocated, then from there it's up to you to figure out where the object travelled and when it should actually have been released.

Static Analyzer will find the cases where you should have released in a few lines of code from when you created the object. Anything else, you just need to use Leaks to get a starting point to track down when you need to release something elsewhere.

Kendall Helmstetter Gelner