15

I want to enable NSZombies for my iPhone app.

I have read several articles online and I am still unsure of the exact procedure.

I know I have to set the Environment Variables, which I have done:

NSZombieEnabled = YES
NSDebugEnabled = YES
NSDeallocateZombies = NO

I think (I'm not sure), I have to import NSDebug.h. When I check the headers of the Foundation Framework in my project, there is no NSDebug.h.

After some research, I found them in the iPhoneSimulator Foundation Framework. So (and I'm not sure if this is correct), I imported the iPhoneSimualtor Foundation Framework into my project. I noticed that the file STILL does not show up in the project window, even though I can locate it in the Finder.(Is this normal behavior?).

So I opened up main and added:

#ifdef TARGET_IPHONE_SIMULATOR
#import <Foundation/NSDebug.h>
#endif

I am not sure if that is right either. After this I still can't get the NSZombie to work (unless I have misunderstood what it is supposed to do) I am expecting to see a log of " NSZombie sent a release... " or something. But I don't see anything

I'm sure I'm just not doing this right, a good step by step would be appreciated. Thanks

Also of note, I have also enabled:

NSMallocStacklLogging = YES
MallocStackLoggingNoCompact = YES
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
Corey Floyd
  • 25,929
  • 31
  • 126
  • 154

3 Answers3

34

Are you setting the environment variable correctly? The step by step guide is

  1. Double-click an executable in the Executables group of your Xcode project.
  2. Click the Arguments tab.
  3. In the "Variables to be set in the environment:" section, make a variable called "NSZombieEnabled" and set its value to "YES".

You don't need to #import NSDebug.h

John Rudy
  • 37,282
  • 14
  • 64
  • 100
Jane Sales
  • 13,526
  • 3
  • 52
  • 57
10

You don't have to include NSDebug.h or import any special frameworks to use NSZombies. Basically, turn 'em on in your environment variables, and then, if you attempt to message a dealloc'd object, THEN you'll see something in your console, along the lines of:

2009-02-10 21:17:08.546 MyApp[16926:20b] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x4babc0

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
  • Thanks, I thought I was getting too involved in this. I set a breakpoint at -[NSZombie release]. It appears to get disabled as execution begins. Is that normal? Also, should my app still crash? I thought since the NSZombie object was still there, my program would continue executing. Thanks – Corey Floyd Feb 11 '09 at 04:40
  • You should get a console message when ANY message is sent to an NSZombie; You should break automatically, no breakpoint required. – Ben Gottlieb Feb 12 '09 at 01:03
3

-1 to Apple. Debug builds should be running with full instrumentation out of the box (with a choice to opt-out). Also see http://www.cocoadev.com/index.pl?NSZombieEnabled for additional itms of interest to someone who is developing and debugging a program.

jww
  • 97,681
  • 90
  • 411
  • 885