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

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I have a timer set up inside a singleton. I can't understand why it's keeping crashing the second time the repeating function gets called!

Code:
static SFSession *_sharedSFSession = nil;

@interface SFSession ()
@property (nonatomic, retain) NSTimer *keepAliveTimer;
- (void)initDefaults;
- (void)reloadKeepAliveTimer;
- (void)keepSessionAliveUsingTimer:(NSTimer *)timer;
@end

@implementation SFSession
@synthesize loginData = _loginData;
@synthesize keepAliveTimer = _keepAliveTimer;

#pragma mark - General Init;
+ (SFSession *)sharedSFSession
{
	@synchronized(self){
		if (_sharedSFSession == nil) {
			self = [[self alloc]init];
		}
	}
	return _sharedSFSession;
}

+(id)allocWithZone:(NSZone *)zone
{
	@synchronized(self){
		if (_sharedSFSession == nil) {
			_sharedSFSession = [super allocWithZone:zone];
			return _sharedSFSession;
		}
	}
	return nil;
}

- (id)copyWithZone:(NSZone *)zone
{
	return self;
}

- (id)retain
{
	return self;
}

- (unsigned)retainCount
{
	return UINT_MAX;
}



- (id)autorelease
{
	return self;
}

#pragma mark - Special Init
- (id) init
{
	self = [super init];
	if (self != nil) {
		[self initDefaults];
	}
	return self;
}

-(void)initDefaults
{
	_loginData = [[SFDreamLoginData alloc]init];
	[self reloadKeepAliveTimer];
}

#pragma mark - Functions
- (void)keepSessionAliveUsingTimer:(NSTimer *)timer
{
	NSLog(@"keeping session alive!");
//	[_keepAliveTimer invalidate];
	
}

- (void)reloadKeepAliveTimer
{
	[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(keepSessionAliveUsingTimer:) userInfo:nil repeats:YES];
}
#pragma mark - 

- (void)dealloc {
    [_loginData release];
	[_keepAliveTimer release];
    [super dealloc];
}

Any help would be greatly appreciated. I am using Xcode 4.1.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.