Question

I appear to have some overzealous releasing going on in my obj-C app - getting error message

"-[myobj release]: message sent to deallocated instance 0x5633b0"

. I know the class of the object instance causing the problem, but this class is used all over to create many instances.

My thought is I could put some logging in the init method of the class to log whatever "0x5633b0" corresponds to which should help me track down where the instance is being created.

What exactly is the "0x5633b0" and is there any way I can get access to that value in the code to log it?

Thanks.

Was it helpful?

Solution

0x5633b0 is likely the address of object in question (the value of self). You can use NSLog or printf with %p to print it.

OTHER TIPS

What worked best for me when I ran into similar problems recently was the following:

  1. Under under Project->Edit Active Executable -> Arguments tab -> Environment variables section I added and set to YES the following variables: NSAutoreleaseFreedObjectCheckEnabled, NSZombieEnabled and NSDebugEnabled.

  2. Under the Run menu, I selected Enable Guard Malloc.

With these settings the debugger provided more hints on what's wrong with my code.

(I found these tips here)

Good luck, Ori

0x5633b0 is likely the address of the deallocated object (the value of myobj). You can use NSLog or printf with %p to print it.

You can also use the instruments profiler to find the deallocated object.

1. Start the profiler:

enter image description here

2. Select the "Zombies" and start the profiler.

enter image description here

3. Click through the simulator until you hit your "deallocated error case"

enter image description here

In the debugger, type info symbol 0x5633b0 and you'll get some indication as to what object it is. One other thing that might be helpful is backtrace which will give you a stack trace. All in all, this blog entry has some great tips.

you can also add these to environment variables:
MallocStackLoggingNoCompact 1

and write in the gdb console:
info malloc-history <paste-address-here>

Reference: here

Consider using the NSZombieEnabled flag.

You will then know what is this deallocated object you're sending a message.

You're not managing your memory properly -- you're calling release/autorelease on some object more times than you're calling retain. Make sure you're following all of the rules laid out in the Memory Management Programming Guide for Cocoa.

0x5633b0 is just the address of the memory location at which the object is stored. One thing you can try to do is to add some code to the init method:

- (void) init
{
    if(self == (MyClass*)0x5633b0)
        NSLog(@"Allocated object at address 0x5633b0");  // put a breakpoint on this line
    // do rest of init...
}

If you have any other init methods (e.g. initWithCoder:, which is called for objects instantiated from a XIB), make sure to put this snippet in those methods as well. Put a breakpoint on the NSLog line, and then see when it gets hit. Note that it may get hit several times, if an object is allocated at that address, deallocated, and then another object happens to be reallocated at the same address. The last hit before the crash is the one you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top