Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
I have a class
Code:
@interface myclass {
NSTimer *timer
}
@property(nonatomic, retain) NSTimer* timer;
@end
and synthesize etc.

I have two timer variables one repeat yes and another repeat no.

the problem is, "repeat Yes" timer crashes when trying to invalidate inside the function which the timer itself had fired.

when i allocate, i see timer = 0x38Axt3 ... like this, valid address.

but when trying to invalidate, the value is 0x5 or 0x3. what's wrong ?

i have made sure everywhere that neither the timer is being released or twice invalidated, that has been proved by putting breakpoints at all invalidate method calls

regards
 
Code:
@implementation
-int
{
    timer = [NSTimer timerWithDuration:0.2 delegate:self   selector:@selector(timerFired);
timer1 = [NSTimer timerWithDuration:0.2 delegate:self selector:@selector(timer1Fired);
}

void timerFired
{
  [timer invalidate]; // this does not have proper address (0x5)
  timer = nil;
  [timer1 invalidate]; // this has proper address
  timer1 = nil;
}
@end
 
oops

i realised, there was no problem with this part of the code, after running cunit tool and fixing some other memory leaks, it vanished . spoilt lot of time and peace.
 
how to stop autoreleasing

isn't there a way to stop autoreleasing altogather and may be check allocation failure ? that would probably a better way of finding exact point of bugs.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.