Reputation: 1435
I am refactoring a program right now. Trying to prevent memory leaks I was looking for objects to enclose in using
blocks when I found a TaskDefinition
object (class found in Microsoft.Win32.TaskScheduler
) that Dispose
was not called on. When I tried to enclose it VisualStudio told me that this class does not implement IDisosable
. Looking at the class this is certainly true:
namespace Microsoft.Win32.TaskScheduler
{
// Summary:
// Defines all the components of a task, such as the task settings, triggers,
// actions, and registration information.
public sealed class TaskDefinition
{
...
// Summary:
// Releases all resources used by this class.
public void Dispose();
}
}
So why would you implement a Dispose
method but not implement the IDisposable
interface? Are there any drawbacks from implementing the interface?
Thank you for helping me to understand this.
Upvotes: 0
Views: 262
Reputation:
From the comments:
According to this page, this is a bug that's fixed in newer versions of the assembly.
An additional note, however: the documentation for IDisposable.Dispose
explicitly requires implementations to support calling Dispose
multiple times, so a valid reason in other cases could be that the class does not support that. In that case, pretending to implement IDisposable
but not meeting its requirements would be worse than not implementing it.
Upvotes: 3