Following is my code:
.h file:
#import "Foundation/Foundation.h"
@interface GObject:NSObject{
NSTimer* m_Timer;
}
@property(nonatomic, retain) NSTimer* m_Timer;
- (void)Initialize;
- (void)TimerCallback:(NSTimer*)pTimer;
@end
.m file:
@implementation GObject
@synthesize m_Timer
- (void) Initialize{
self.m_Timer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector: @selector(TimerCallback:)
userInfo: nil
repeats: YES];
}
- (void)TimerCallback:(NSTimer*)pTimer {
//Some Code
}
- (void)dealloc {
[m_Timer invalidate]; //--Crashes Here
[m_Timer release];
m_Timer = nil;
[super dealloc];
}
@end
Now when the dealloc gets called, the program crashes in the line invalidating the timer. The next two lines don't even get called. I get a "EXC_BAD_ACCESS" error. Can anyone tell me why that might be happening, and what is the proper way of stopping and releasing a NSTimer member variable in a class.