Memory management / debugging references

9 views
Skip to first unread message

Brad Larson

unread,
Jul 22, 2009, 5:09:49 PM7/22/09
to madison-coco...@googlegroups.com
I promised to pass along the references that I mentioned at
yesterday's CocoaHeads meeting on memory management and debugging.
First, the CocoaHeads San Francisco video of Wil Shipley's talk about
what he learned from developing his iPhone application (including
memory management issues) can be found at

http://www.vimeo.com/4421498

There might be a higher quality version available as a torrent, check
the original announcement of his talk here:

http://www.theocacao.com/document.page/604

Also from the San Francisco CocoaHeads is a talk on debugging tips and
tricks:

http://www.viddler.com/explore/cocoaheads/videos/6/

One of the specific tricks that I mentioned was a global breakpoint
for picking up exceptions. To add this, go to Run | Show |
Breakpoints in Xcode, then click on the "Global breakpoints" item in
the list on the left. Add a breakpoint for objc_exception_throw in
the libobjc.A.dylib location. With this breakpoint added, if you
enable breakpoints, then run your application under the debugger, the
instant you do something that throws an exception, the program counter
will halt on the line where the exception occurred and you'll get a
full stack trace to figure out what went wrong.

For those of you who haven't watched the Stanford iPhone programming
course videos, Loren Brichter (the author of Tweetie) goes into memory
management during a very nice presentation on the development and
marketing of Tweetie. His comments on UIWebView echo my experience
with it. The Stanford iPhone Application Programming course videos
can be found on iTunes at

http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.2024353965.02024353968

They are very well done and are worth watching.

I mentioned two environment settings that you can use to debug your
application. The first, NSZombieEnabled, turns deallocated objects
into NSZombies, which throw exceptions when any message is passed to
them. If you apply the above breakpoint on exceptions, run your
application in the debugger, and use this environment variable, you
can often find the root cause of an overreleased object.

To enable this setting, go to the Targets tab in Xcode, then to your
application's name under the Executables grouping. Bring up the
inspector on this executable and go to the Arguments tab. Add
NSZombieEnabled as a variable to be set in the environment and set its
value to YES. When done with debugging using this flag, remember to
remove it or your application will leak memory like a sieve.

Another environment variable that you can use is CA_PRINT_TREE, which
if set to 1 will cause the entire Core Animation layer tree to be
dumped to disk every time something animates or is changed in your
user interface. It's handy for checking the frames and transforms
applied to all of your views and layers.

It sounds like people would be interested in hearing more about
specific debugging techniques next meeting, so that's a potential
topic of discussion. If anyone has other suggestions or things they
would like to present, feel free to share them.

______________________
Brad Larson, Ph.D.
Sunset Lake Software
http://www.sunsetlakesoftware.com

Reply all
Reply to author
Forward
0 new messages