3

I receive an error "[myObject method]: message sent to deallocated instance 0xbc05440". This must be because I released something I still need.

I hunted around for appropriate nils, releases, etc, but I can't find where I release this object.

I then placed a break inside myObject's dealloc. This catches the dealloc, but the stack is only showing assembly code. If i step from this place, i dont get any hints. How do I find where the dealloc starts?

BankStrong
  • 419
  • 9
  • 21

1 Answers1

5

A likely suspect for your problem is autoreleased variables. They're the sneaky ones that will be released without you explicitly releasing them. So be sure you're not using an autoreleased variable and expecting it to stick around.

As for your specific question, you don't actually care about dealloc's call stack. dealloc is never called right when you release something. The actual deallocating of objects is handled by the runtime outside the normal run-loop context of your app, so looking at the call stack at that point will tell you absolutely nothing.

What you do care about is release. If you want to know when your object is being released, you can override release in the object of interest, and simply call right through to super's implementation. You can then set a breakpoint there to see the current call stack at the time of release. For clarity, it would look like this:

- (oneway void)release {
    [super release]; // Put a breakpoint here.
}

Just something to be aware of: You'll likely see more releases than you expect. This is because the system will retain and release classes internally quite frequently, so you'll need to use discretion when determining what releases are actually worth noting. This approach is just a rough tool. NSZombies are also very useful for tracking down over-released objects.

Community
  • 1
  • 1
Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • Fantastic explanation. I used nszombies earlier, but it didn't help me on this issue. The release break worked like a charm. – BankStrong Aug 24 '11 at 20:55