• 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
NSTimer won't stop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTimer won't stop


  • Subject: NSTimer won't stop
  • From: Michael Becker <email@hidden>
  • Date: Tue, 11 Oct 2005 16:53:48 +0200

Hi,

I have a problem with NSTimer. When my application needs to load a lot of big images, I do that in a thread. I want to display that load process to the user, so in my main thread, I set up a timer that refreshes my application's custom image view every 0.1 seconds. The view is a custom view designed to show a certain number of images and documentation tells me to always load GUI refreshes from the main thread. This mechanism works very well so far.
However, the timer doesn't stop, which leads to my application spending almost 80% of available CPU on redrawing the view, even when the loading is finished and it should do nothing.
Here are the important parts of my code:


This is how I set up my timer (in my SourceController class, in the main thread), refreshDisplayTimer is an instance variable of the SourceController class:

refreshDisplayTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target:self selector:@selector(updateDisplay:) userInfo:nil repeats:YES];

Just before my thread exits, I call a "cleanup" method like so (from within the thread function):

[self performSelectorOnMainThread:@selector (threadReloadFinished) withObject:nil waitUntilDone:NO];

And this is what is being called (in SourceController again):

- (void)threadReloadFinished {
    // Invalidate display timer
    NSLog(@"Done");
    [refreshDisplayTimer invalidate];
    ...
}

For the sake of completeness, here is the updateDisplay method, which is called by the timer:

- (void)updateDisplay:(NSTimer*)timer {
    NSLog(@"redraw");
    [pictureView setNeedsDisplay:YES];
}

The "Done" is printed correctly after loading which shows that the cleanup method is being called. However, if I print out the timer's retain-count from within my updateDisplay method, it shows that the retain count is 2.
I know that the RunLoop retains the timer so I don't retain it myself, but why is the retain count 2?


Can anybody understand what's going on?

Regards,
Michael
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTimer won't stop (SOLVED)
      • From: Michael Becker <email@hidden>
  • Prev by Date: Re: -observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
  • Next by Date: Re: awakeFromNib not called
  • Previous by thread: dragImageForRowsWithIndexes :::: (NSPointPointer) dragImageOffset?
  • Next by thread: Re: NSTimer won't stop (SOLVED)
  • Index(es):
    • Date
    • Thread