This is something that has puzzled me for awhile.
I have a NSTimer, added to the currentRunLoop, and if I don't retain it, it crashes.
NSTimer *timer = [[NSTimer timerWithTimeInterval:60.0 target:self selector:@selector(tryUnion:) userInfo:nil repeats:NO] retain];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
I have read that I don't need to retain it, as addTimer to the NSRunLoop does that.
later I invalidate and release (if I don't retain above, I don't release below- that's the crashing case):
- (void) tryUnion:(NSTimer*)aTimer {
[aTimer invalidate];
[aTimer release];
}
My questions are 1) How should I write this, if its possible to do what i've done without the retain/release. 2) analyze flags this or a potential leak of the object in "timer". As written here, is there the possibility of leaks, or is it just that analyzer isn't smart enough to know that there is a release in the function called by the timer?