Wednesday, April 6, 2011

Cocoa application appears to crash when the main window is closed

My application seems to have acquired a slightly odd behaviour when it terminates. When I close a the main window using the standard little red button in the top left the application crashes. I haven't made any changes to the application that would obviously cause this problem. I'm struggling to debug the problem because the application crashes and my debugging skills are limited. Does anyone know any obvious reason why this might occur or a debugging strategy that I might be able to adopt?

From stackoverflow
  • If it crashes with EXC_BAD_ACCESS (which sounds likely, although may not be the case - you didn't specify), it is likely something to do with one of your dealloc methods somewhere. The app dealloc's everything right before quitting, so make sure you aren't releasing something that has been autoreleased, for example.

    If you are comfortable using GDB, I would try setting breakpoints maybe in something dealloc methods and just see what state the stuff you're releasing may be in.

    Crashes like these can be tricky to debug without doing some exploration first to find out what is actually causing the problem.

    Ian Turner : Thanks for the help, just spotted the problem and it was a rogue dealloc. Hopefully my rather silly error might be useful to pointing out the problem to someone else in the future.
  • One new option in IB 3 is a setting for NSWindows to release when closed. Make sure you have that checked off and/or are retaining the window properly/

  • I would also say it must be some kind of memory leak. You mention that your debugging skills are limited, but it is actually quite easy do debug those with the new Instruments app. Here is a very nice article about it.

0 comments:

Post a Comment