views:

83

answers:

1

Here's the part of the code dealing with it:

NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:1.0+index];
        NSTimer *timer = [[NSTimer alloc] initWithFireDate:fireDate
                                                    interval:0.5
                                                    target:self
                                                  selector:@selector(countedtargetMethodGlow:)
                                                  userInfo:nil
                                                   repeats:NO];

NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
[timer release];

But it's in a loop, so I'll be making a buncha these, and I don't know what I need to leave alone for the firing not to be messed up.

A: 

Every timer object you add to a run loop is retained by the run loop until it's invalidated (effectively indicating that the run loop is taking "ownership" of the timer while it needs it). So you can release any of those timers without affecting how they're scheduled on the run loop. If you need them for some independent purpose you should not release them, so they're guaranteed to still be around for you even if the run loop has finished with them.

Graham Lee
So if I reassign the timer to another process I want done, and then the first process releases the timer, wouldn't that screw up the second process?
marty
No, if your coding follows normal Cocoa rules. Every object retains its instance variables, and releases them when done. That way the retain counts will balance. What you may be missing is that an object is only deallocated when the retain count reaches zero.
Paul Lynch