• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimer memory management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSTimer memory management
      • From: "email@hidden" <email@hidden>
  • Prev by Date: CGDisplayChangeSummaryFlags
  • Next by Date: Re: [ANN] Release: NanoStore 1.0 for Mac and iOS
  • Previous by thread: Re: NSTimer memory management
  • Next by thread: Re: NSTimer memory management
  • Index(es):
    • Date
    • Thread