-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
We've learned the hard way that if Stop() is not called on DispatcherTimer instances, once they are started, they continue to live forever, even if nothing references the instance anymore.
After looking at the implementation of DispatcherTimer, we noticed that when calling Start(), a reference to the DispatcherTimer is added to the Dispatcher.CurrentDispatcher (which is static) and the reference is only removed once the Stop() method is called.
Now knowing that Stop() must always be called in order to avoid memory leaks, shouldn't the class implement IDisposable and make sure to call Stop() in the Dispose()? This would indicate the consumer of the class that it needs to be disposed for resources to be released.
Same way System.Threading.Timer implements IDisposable, I think DispatcherTimer should as well.