views:

20

answers:

1

I'm at my wits end. I'm trying to debug a crash, and finally I manage to track it down. My 'minutesLeft' variable is somehow being released.

Problem is, I never set it to release, and the property is set to retain. I can't figure out what is going on!

Using the zombie variable, I got the following message: * -[CFNumber intValue]: message sent to deallocated instance 0x728fdd0

and tracked it down to the following line of code:

NSLog(@"MeterViewController minutesLeft %i", [minutesLeft intValue]);

The problem is when I declare the property... @property (nonatomic, retain) NSNumber *minutesLeft; So the property should be handling the retain for me!

The value is set using...

minutesLeft=[NSNumber numberWithInt:row];

and...

minutesLeft=[NSNumber numberWithInt:(((timeLeft)/60)%60)];

For dealloc and viewDidUnload I have

self.minutesLeft=nil;

but since I'm not leaving the view, those shouldn't be effecting anything.

Anyone have any ideas?

+3  A: 

You are setting the local variable that is the backing for the property, not the property itself. Thus it doesn't get retained. Try:

self.minutesLeft = [NSNumber numberWithInt:row]

or

self.minutesLeft = [NSNumber numberWithInt:(((timeLeft)/60)%60)];

(Note the self.)

You are doing it correctly when deallocating though (setting self.minutesLeft = nil).

calmh
Doesn't it just figure that the code written by someone else would be the code doing it right. I thought the two were synonymous :(
RonLugge