<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,6 +6,15 @@
 
 #import &quot;YRKSpinningProgressIndicator.h&quot;
 
+
+@interface YRKSpinningProgressIndicator (YRKSpinningProgressIndicatorPrivate)
+
+- (void) setupAnimTimer;
+- (void) disposeAnimTimer;
+
+@end
+
+
 @implementation YRKSpinningProgressIndicator
 
 - (id)initWithFrame:(NSRect)frame {
@@ -20,6 +29,19 @@
     return self;
 }
 
+- (void)viewDidMoveToWindow
+{
+	[super viewDidMoveToWindow];
+	
+	if ([self window] == nil) {
+		// No window?  View hierarchy may be going away.  Dispose timer to clear circular retain of timer to self to timer.
+		[self disposeAnimTimer];
+	}
+	else if (_isAnimating) {
+			[self setupAnimTimer];
+	}
+}
+
 - (void)drawRect:(NSRect)rect {
 	int i;
 	float alpha = 1.0;
@@ -90,22 +112,40 @@
     [self setNeedsDisplay:YES];
 }
 
+- (void) setupAnimTimer {
+	// Just to be safe kill any existing timer.
+    [self disposeAnimTimer];
+	
+	if ([self window]) {
+		// Why animate if not visible?  viewDidMoveToWindow will re-call this method when needed.
+		_animationTimer = [[NSTimer timerWithTimeInterval:(NSTimeInterval)0.05
+												   target:self
+												 selector:@selector(animate:)
+												 userInfo:nil
+												  repeats:YES] retain];
+											  
+		[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSRunLoopCommonModes];
+		[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSDefaultRunLoopMode];
+		[[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSEventTrackingRunLoopMode];
+	}
+}
+
+- (void) disposeAnimTimer {
+    [_animationTimer invalidate];
+	[_animationTimer release];
+	_animationTimer = nil;
+}
+
 - (void)startAnimation:(id)sender {
 	_isAnimating = YES;
-    _animationTimer = [[NSTimer timerWithTimeInterval:(NSTimeInterval)0.05
-                                               target:self
-                                             selector:@selector(animate:)
-                                             userInfo:nil
-                                              repeats:YES] retain];
-                                          
-    [_animationTimer setFireDate:[NSDate date]];
-    [[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSDefaultRunLoopMode];
-    [[NSRunLoop currentRunLoop] addTimer:_animationTimer forMode:NSEventTrackingRunLoopMode];
+	
+	[self setupAnimTimer];
 }
 
 - (void)stopAnimation:(id)sender {
 	_isAnimating = NO;
-    [_animationTimer invalidate];
+	
+	[self disposeAnimTimer];
     
     [self setNeedsDisplay:YES];
 }</diff>
      <filename>Code/YRKSpinningProgressIndicator.m</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d6fe347d6d9d3f0c72f435dcf79b64a5d3b82005</id>
    </parent>
  </parents>
  <author>
    <name>Kelan Champagne</name>
    <email>kelan@yeahrightkeller.com</email>
  </author>
  <url>http://github.com/kelan/yrk-spinning-progress-indicator/commit/207c8b4c7cf4f6efd0d8de05fe74acc867f48e79</url>
  <id>207c8b4c7cf4f6efd0d8de05fe74acc867f48e79</id>
  <committed-date>2009-06-02T21:31:25-07:00</committed-date>
  <authored-date>2009-04-30T21:51:29-07:00</authored-date>
  <message>Add patch from Eric Roccasecca (via email)

Guards against an issue when starting the spinner multiple times. It will
now always kill the timer and make a new one when told to start animating,
instead of starting more times (which cause the animation to run faster
and faster).

Also fixes a potential leak of the spinner object. The spinner object
would never get fully released if it was animating since timers retain
their targets. Does this by implementing -viewDidMoveToWindow to handle
the case where the window is nil and kills the timer in that case.</message>
  <tree>61935a5308f172f7da9bbe05d926a9ab79b43583</tree>
  <committer>
    <name>Kelan Champagne</name>
    <email>kelan@yeahrightkeller.com</email>
  </committer>
</commit>
