Checking Malloc History

Sometimes it is useful to see what malloc operations have been performed by a given application. Doing this is a fairly straightforward process that can be facilitated with the command malloc_history, but requires a little bit of setup for iPhone-specific apps since the console cannot be used directly.

  1. Go under the Executables directory of your project in XCode.
  2. “Get Info” on your application.
  3. Click on the “Arguments” tab
  4. Under Environment variables set MallocStackLogging and NSZombieEnabled to YES. The former allows for malloc_history to be used, the latter logs deallocated memory, which can help find the memory address.
  5. Run the app using the debugger (Command-Option-Y)
  6. Check the console or probe around with the debugger to find the memory address you want to check.
  7. Go to top of the Debugger Console and look for a line that looks like this:
launchd(28861) malloc: stack logs being written into /tmp/stack-logs.28861.launchd.7lhXSV
  1. Taking the pid from that statement (28861) in this case and the memory address you picked up earlier (from, for example, a debug output line that looks something like this: -[NGTableViewDelegate tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x104f650 or from otherwise looking around with the debugger).
  2. Type malloc_history the command line or shell malloc_history from inside of GDB.

This can help track down tricky problems with delegate objects.

This entry was posted in Uncategorized. Bookmark the permalink.

Error: The ad management script is not properly configured for this user

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>