Cocoa

Finding Where You Doubly Released a Cocoa Object's Memory

So while working on CocoaREST, I was just about to commit an enhancement to support file uploading, like to update your Twitter profile picture, and I kept spawning a crash with the following error:

objc[<pid>]:FREED(id): message release sent to freed object="<memory_address>"

After scouring the code, I couldn't figure out where I was doubly releasing memory. Hitting up Google, I found the following: http://iphone-crack-addict.blogspot.com/2009/06/debugging-objc17695-freedid-message.html. This article helped introduce me to a few really good environment variables I could set that would allow me to identify where I was creating this problem. Here are the environment variables:

With these two set to "YES" in your executable's Arguments tab, you then have the ability to figure out where you're doubly releasing an object's memory using in gdb:

shell malloc_history <pid> <memory_address>

(Note: To set these environment variables, double-click the executable in Xcode's Executable's group, click the Arguments tab and then add the variables.) And there you have it. Thanks go out to the The Journey of an iPhone Developer blog for helping me extend my Xcode/Cocoa knowledge.

Syndicate content