Hi,
I have been trying to implement a 1 second repeating timer, but its leading to retaining the target object of a thread from which I'm launching this timer thread.
Here's my implementation.

I'm running this method from my thread.
- (void)setUpTimer
{
timerThread = [[NSThread alloc] initWithTarget:self selector:@selector (startTimer) object:nil];
        [timerThread start];
}

- (void)startTimer
{
timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(myTimerFireMethod:) userInfo:nil repeats:YES];
        NSRunLoop *theRL = [NSRunLoop currentRunLoop];
        [theRL addTimer:timer forMode:NSDefaultRunLoopMode];
while (keepTimerRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
}

- (void)myTimerFireMethod:(NSTimer*)theTimer
{
        [self setUpdateStatus:YES];
}

From my thread I'm doing something when updateStatus is YES and then I'm setting it to NO, which is again set to YES by this timer, so that I get to do something at 1 second interval. But its leading to referencing the target object of my thread, by 3-4 non-objects (bytes), which shows different descriptions every time as per GC Monitor Instrument (kind of undefined behavior).

Whats wrong with the above scheme, or how can I make it safe?
Googled a lot but couldn't find a simple timer example that would suit my need. Can you point me to some example code etc.?

Wishes,
Nick

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to