This code works well
@property (nonatomic, retain) NSTimer *timer;
self.timer = [[NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO] retain];
this code get CFRelease . But why? i use retain property
self.timer = [NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO];
Not a lot to go on... but:
That'll end up retaining the timer 3 times and self once.
Timer +1 for the property assignment
self
+1 for being the target of the timerThe timer will be released once when fired (because it'll be unscheduled from the run loop).
self
will be released when the timer is invalidated or released (you shouldn't have to care).So, you have two retain counts to account for. The call to
retain
in the code above is noise; don't bother as the property assignment will retain it.That leaves the property's retain. The most obvious way is to release the timer in -dealloc.
However, unless you need to potentially invalidate the timer before it fires, there is no reason to have an instance variable referring to the timer at all. Even if you do have an iVar, there is no reason to retain the timer either as long as you set self.timer = nil in your
timerFired:
method (and set it to nil if you invalidate anywhere).