Reputation:
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.
Upvotes: 25
Views: 52165
Reputation: 3882
Consider using the NSZombieEnabled flag.
You will then know what is this deallocated object you're sending a message.
Upvotes: 0
Reputation: 11161
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:
2. Select the "Zombies" and start the profiler.
3. Click through the simulator until you hit your "deallocated error case"
Upvotes: 14
Reputation: 5666
you can also add these to environment variables:
MallocStackLoggingNoCompact 1
and write in the gdb console:
info malloc-history <paste-address-here>
Reference: here
Upvotes: 0
Reputation: 12830
What worked best for me when I ran into similar problems recently was the following:
Under under Project->Edit Active Executable -> Arguments tab -> Environment variables section I added and set to YES
the following variables: NSAutoreleaseFreedObjectCheckEnabled
, NSZombieEnabled
and NSDebugEnabled
.
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
Upvotes: 42
Reputation: 6360
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.
Upvotes: 11
Reputation: 400224
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.
Upvotes: -12
Reputation: 40336
0x5633b0
is likely the address of object in question (the value of self
). You can use NSLog
or printf
with %p
to print it.
Upvotes: 30