This seems like a good way to go. Thanks for the tip.
On Nov 8, 2007, at 12:01 PM, Michael Nickerson wrote:
On Nov 8, 2007, at 1:05 PM, John Stiles wrote:
I have a method that needs to schedule a "cleanup pass" to occur
in the near future. The method might be called once, ten times, or
a hundred times in a row, but I only need to clean up one time. To
implement this, I used the following pattern, and I'm wondering if
it was the best way to go.
First, when the object is first created, I create a timer. I
scheduled its fire date to be in the distant, distant future:
Of course, there's caveat's doing it this way: your cleanup method
will need to know what objects are actually being cleaned up, as
it's not passed that info. Doing it this way, though, your cleanup
method would only be called once, and would only get called when
objects actually need to be cleaned up.
I'm not entirely certain how you have your code setup, so I don't
know if this would be the best method to use. But if you have some
sort of central object that does cleanup of other objects, this
would be a good alternative.
I use this with sliders that are updating something in the GUI
mostly, so that it's not updating every single time the slider's
value changes. You can, of course, adjust the delay to whatever
works best for you, and if you want it to run in run loop modes
other than NSDefaultRunLoopMode you can add in the inModes: option
to the performSelector:... method and pass it an array of run loop
modes you'd like it to run in.