Ashish Agarwal
Ashish Agarwal

Reputation: 14925

Using Zombies in Xcode

I am using Zombies to try and get rid of an EXC_BAD_ACCESS error.

In Zombies, I got this message when the app crashes -

An Objective-C message was sent to a deallocated object (zombie) at address: 0x8955310.

My question is what do I do next to solve the problem ?

Upvotes: 1

Views: 1980

Answers (2)

rob mayoff
rob mayoff

Reputation: 385960

Turn on malloc stack logging and zombies for your scheme in Xcode, and run the app in the simulator. Xcode should enter the debugger when the message is sent to the zombie. Run this command at the debugger prompt:

info malloc 0x8955310

(Substitute the actual address of the zombie!) You'll get stack traces from when that address was allocated and freed.

Upvotes: 4

James Raitsev
James Raitsev

Reputation: 96491

Most likely you have created an object, released it and later sent it a message.

To make sure this won't happen, a safe practice would be to set your object to nil once you are done using it

Consider:

NSMutableArray *a = [NSmutableArray array];
[a dealloc];
[a do_something_weird];

Your app is likely crash (won't always crash) in response to this message, as after release, you don't own this memory, and it may be used by some other object.

If you change this sequence to

NSMutableArray *a = [NSmutableArray array];
[a dealloc];
a=nil;
[a do_something_weird];

Exactly nothing will happen. This is a safe practice to follow when you are sure you're done using the object.

You also may want to consider using the Automatic Reference Counting feature, which helps a lot with memory management.

Upvotes: 1

Related Questions