Re: NSTimer memory management
Re: NSTimer memory management
- Subject: Re: NSTimer memory management
- From: Gregory Weston <email@hidden>
- Date: Thu, 23 Sep 2010 06:59:15 -0400
email@hidden wrote:
> Is this an over-release?
>
> timer = [ [NSTimer scheduledTimerWithTimeInterval: ...] retain];
> ...
> [timer invalidate];
> [timer release];
Seems fine, although based on <http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Timers/Articles/usingTimers.html#//apple_ref/doc/uid/20000807-CJBJCBDE> it also seems redundant. Consider the following excerpts:
-----
@interface TimerController : NSObject {
NSTimer *repeatingTimer;
}
@property (assign) NSTimer *repeatingTimer;
@end
...
- (IBAction)startRepeatingTimer:sender {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self selector:@selector(timerFireMethod:)
userInfo:[self userInfo] repeats:YES];
self.repeatingTimer = timer;
}
...
- (IBAction)stopRepeatingTimer:sender {
[repeatingTimer invalidate];
self.repeatingTimer = nil;
}
-----
Note that repeatingTimer is not retained or released by the sample code. Have you hit it with Xcode's analyzer yet to see what else might be tripping it up?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden