310

I have an app that is crashing with no error tracing. I can see part of what is going on if I debug, but can't figure out which object is "zombie-ing".

Does anybody know how to enable NSZombie in Xcode 4?

Gumbo
  • 643,351
  • 109
  • 780
  • 844
jason
  • 5,391
  • 6
  • 23
  • 26

15 Answers15

445

Environment variables are now part of the "scheme".

To edit the scheme and turn on zombies:

  • In the "Product" menu, select "Scheme" > "Edit Scheme...".

  • Go to the "Run Foo.app" stage in the left panel, and the "Arguments" tab on the right.

  • Add NSZombieEnabled to the "Environment Variables" section and set the value to YES, as you could in Xcode 3.


In Xcode 4.1 and above, there's also a checkbox on the "Diagnostics" tab of the "Run" stage to "Enable Zombie Objects".


With Xcode 6.4:

Screenshot

一二三
  • 21,059
  • 11
  • 65
  • 74
  • 5
    Doesnt break on the call to the deallocated object on device, any way to make that happen? – jjxtra Oct 21 '11 at 15:31
  • 97
    It changed again in 4.2, see my answer below. Go to Product->Edit Scheme->Diagnostics – Moshe Kravchik Nov 16 '11 at 12:29
  • In Xcode, in the Help menu at the top (last one on the right) search for "Edit Scheme" it will point you in the right direction every time in any version. – unom Mar 03 '14 at 21:16
  • If we enable this NSZombieEnabled feature to our app shall we release the app to store..? Because I saw one post saying that its not good practice to release to store when we enable this feature. – SURESH SANKE Feb 24 '15 at 10:14
  • 2
    For the rookies coming after, in Xcode 6.1 you go menu Product> Scheme-Edit Scheme>Diagnostics tab>Checkbox Enable Zombie Objects – Joshua Dance Mar 03 '15 at 17:49
146

I encountered the same problem with troubleshooting EXC_BAD_ACCESS and had hard time to find the setting with Xcode 4.2 (the latest one that comes with iOS5 SDK). Apple keeps on moving things and the settings are no longer where they used to be.

Fortunately, I've found it and it works for the device, not just Simulator. You need to open the Product menu in the Xcode, select Edit scheme and then choose the Diagnostics tab. There you have "Enable Zombie Objects". Once selected and run in debugger will point you to the double released object! Enjoy!

In short

Product->Edit Scheme->Diagnostics-> Click Enable Zombie Objects
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Moshe Kravchik
  • 2,341
  • 2
  • 16
  • 18
  • 2
    In Xcode, in the Help menu at the top (last one on the right) search for "Edit Scheme" it will point you in the right direction every time in any version. – unom Mar 03 '14 at 21:16
43

Product > Profile will launch Instruments and then you there should be a "Trace Template" named "Zombies". However this trace template is only available if the current build destination is the simulator - it will not be available if you have the destination set to your iOS device.

Also another thing to note is that there is no actual Zombies instrument in the instrument library. The zombies trace template actually consists of the Allocations instrument with the "Enable NSZombie detection" launch configuration set.

Shane Fitzgibbon
  • 926
  • 7
  • 11
  • 13
    "However this trace template is only available if the current build destination is the simulator". Thank you! – ajh158 Aug 24 '11 at 12:19
  • In Xcode, in the Help menu at the top (last one on the right) search for "Edit Scheme" it will point you in the right direction every time in any version. – unom Mar 03 '14 at 21:17
25

It's a simple matter of setting an environment variable on your executable (NSZombieEnabled = YES), and then running/debugging your app as normal.If you message a zombie, your app will crash/break to debugger and NSLog a message for you.

For more information, check out this CocoaDev page: http://www.cocoadev.com/index.pl?NSZombieEnabled

Also, this process will become much easier with the release of 10.6 and the next versions of Xcode and Instruments. Just saying'. =)

MAhipal Singh
  • 4,745
  • 1
  • 42
  • 57
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
22

Product > Profile will pop up Instruments. Select zombies from the panel and go nuts.

pseudosudo
  • 6,270
  • 9
  • 40
  • 53
17

Go to Product - Scheme - edit scheme - Arguments - Environment Variables set NSZombieEnabled = YES

enter image description here

enter image description here

PJR
  • 13,052
  • 13
  • 64
  • 104
12

In xcode 4.2

Goto, Product -> edit scheme -> click Run yourappname.app -> Diagonostics -> Enable Zombie object.

Dax
  • 6,908
  • 5
  • 23
  • 30
11

Here's a video and explaination how to use Instruments and NSZombie to find and fix memory crashes on iOS: http://www.markj.net/iphone-memory-debug-nszombie/

Mark Johnson
  • 1,105
  • 9
  • 8
6

As of Xcode 3.2.5 and Snow Leopard (Mac OS X 10.6), you can run your code through the Zombies instrument: Run > Run with Performance Tool > Zombies. That allows you to see particular objects and their retain counts on a timeline.

Dov
  • 15,530
  • 13
  • 76
  • 177
  • 1
    I can see zombies option but it is grayed out. Do you know how it is enabled? – Rahul Vyas Jul 15 '11 at 07:29
  • @RahulVyas, I've never seen that before, but do you have garbage collection turned on? I could see Zombies not making sense in that context – Dov Jul 18 '11 at 11:43
  • I have turned on garbage collection in the settings it shows supported [-fobjc-gc] but still that option is disabled. Infact only last 5 options are enabled in the instruments category. Any other idea? Or am I doing something wrong? – Rahul Vyas Jul 18 '11 at 12:01
  • @RahulVyas: Sorry, to be clearer, I thought turning garbage collection _off_ would possibly enable Zombies, since I don't think it's possible to have a zombie with garbage collection. If that doesn't solve it, I would recommend reading the Instruments documentation (they have good write-ups on each instrument) and if you still haven't gotten it, post a question here to get wider attention (and ultimately an answer). – Dov Jul 18 '11 at 16:21
4

In Xcode 4.5.2 goto Product -> Edit Scheme -> and Under the Diagnostics tab check the check box in between Objective C and Enable Zombie Objects and Click on OK

Gani414
  • 93
  • 2
  • 12
3

To enable Zombie logging double-click the executable in the executables group of your Xcode project. At this point click the Arguments tab and in the Variables to be set in the environment: section, make a variable called NSZombieEnabled and set its value to YES.

DreamOfMirrors
  • 2,147
  • 1
  • 21
  • 34
3

In XCode 4.0: To detect NSZombie in Instruments, select the Simulator as your target (can't detect NSZomboe on device). Run Instruments (CMD+I) and select "Zombies" trace template. Enjoy.

Ehud B
  • 31
  • 3
2

in ur XCODE (4.3) next the play button :) (run)

select : edit scheme

the scheme management window will open

click on the Arguments tab

you should see : 1- Arguments passed on launch 2- environment variables

inside the the (2- environment variables) place Name: NSZombieEnabled
Value: YES

And its done....

Rabih harb
  • 1,372
  • 12
  • 11
2

In the preferences of your executable add the environment variable NSZombieEnabled and set the value to YES.

1

NSZombieEnabled is used for Debugging BAD_ACCESS,

enable the NSZombiesEnabled environment variable from Xcode’s schemes sheet.

Click on Product⇒Edit Scheme to open the sheet and set the Enable Zombie Objects check box

this video will help you to see what i'm trying to say.

Community
  • 1
  • 1
user2554822
  • 191
  • 2
  • 7