0

I have a view with some buttons, text fields, and methods. When I load the view, switch to another view, and then switch back, my app crashes. I added in an NSLog in each method to see what the last method call before the crash was, and it was -(void)dealloc{

I am wondering why this method was called? Is it called every time you reload a view? I've double checked my code and I definitely do not call it anywhere.


EDIT : Found my problem, I was releasing an array that I was using to store views. Thanks to @Darren I traced my problem.

BloonsTowerDefence
  • 1,184
  • 2
  • 18
  • 43

2 Answers2

0

Dealloc is called when a class is no longer needed and removed from memory. When you have no more pointers holding onto anything in the view, then it's dealocated.

How are you switching to/from the view?

if you set a (strong) pointer to the view then it won't be dealocated automatically.

Darren
  • 10,182
  • 20
  • 95
  • 162
0

-dealloc is called whenever an object's reference count drops to 0. To find your problem, figure out what object's -dealloc was called. What's the second method on the call stack? The third? Was -dealloc sent to a valid object pointer in the first place?

There are several ways to approach this sort of thing. A good first step is to turn on NSZombies (Google for it). That'll let you know if you're sending a message (like, say, dealloc) to an invalid object. Usually, that causes a crash, but with NSZombies you'll get a nice error message instead.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • using the zombies I have found that I trying to deallocate something that has already been deallocated. It gives me the hex value, but I am not sure where to look for this ? (I am relatively new to Xcode). – BloonsTowerDefence Jul 16 '12 at 22:03