views:

168

answers:

2

I'm newish to Objective-C and my memory management skills are not great. However, I haven't had a single problem until now. And now I've got big problems.

I've gone from zero crashes to crashing at random points, giving me either no console output or unrecognized selector errors on random types (-[NSCFSet isSameAsStop:]: unrecognized selector - I don't even use any sets and I surely have not called my custom isSameAsStop on any sets.). Judging by the randomness and errors, it seems like a memory thing to me although I'm not entirely sure.

How do I go about debugging this? The debugger assumes you know where your problem is... and mine is just everywhere. Ideas?

SOLUTION COMMENT

Some clarification on the solution suggestion to "run with zombie detection enabled":

  • Set the NSZombieEnabled to YES on the Executables' Arguments screen.
  • Build and then choose Run with Performance Tool > Object Allocations, which will start Instruments.
  • Click the "i" button on Object Allocations in Instr. and select zombie detection and retain counts.
  • Rerun and click around in your app, it'll tell you when you hit a zombie!

Thanks for the help!

+5  A: 

You have a classic over-release bug on your hands. Somewhere, you are over-releasing an instance of the class that implements isSameAsStop and it just so happens that an NSSet instance is allocated at the same spot after the original instance is deallocated.

The first step is to "build and analyze" your code, fixing any problems that the static analyzer finds.

The next step is to then run with zombie detection enabled.

bbum
It's a good idea to set the "run static analyzer" option in your project's build settings. That way, you'll get a static analysis every time you build your project.
JeremyP
A: 

In Xcode: Build menu >> Build and Analyze

Finds a lot of common memory management issues.

macatomy