Click here to Skip to main content
14,868,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I normally use the full pattern, but, I'm curious, since I'm using managed resources, for example, the Texture class from SlimDX, which, I'm guessing already implements the full pattern, is it really needed?

For the moment I'm using plain calls like this in my classes.

C#
public class MyClass // I'm not even using the IDisposable interface right now.
{
    Texture texture;

    public void Dispose() // I'm simply calling the underlying dispose methods on objects.
    {
        texture.Dispose();
    }
}


So, yeah, are there any benefits to switching over to the full pattern, or am I just wasting time, and making my code slower(a little overhead here, and there, etc,. It adds up.) for no reason by using the full pattern?

Thanks. :)
Posted
Updated 10-Jan-12 16:31pm
v2
Comments
Kethu Sasikanth 10-Jan-12 20:21pm
   
If the Dispose() call is mandatory then the class documentation should indicate that. The Dispose() is not language feature but the garbage collection is. But I have seen some people coding [myObj.Dispose(); myObj=null;] for any object instance. I donot admire or criticize or comment but I check whether coding of the task is complete or not.
[no name] 10-Jan-12 20:41pm
   
You misunderstand, it is mandatory to call Texture.Dispose, I'm aware of this.

Imagine this class.

<pre lang="c#">
public class Test
{
Texture texture;

public void Dispose()
{
texture.Dispose();
}
}
</pre>

I'm asking whether I really need to bother with adding the full dispose pattern in my Test class. (Since Texture already more than likely implements it in it's entirety. ie, is it redundant, or necessary.)

Hope this clears things up.

1 solution

IMO, if the SLimDX class already implements IDisposable and you are sure about that, you don't need to re-implement it.

You can read more about Deterministic Garbage Collection here[^]. Its one of the best articles I've come across.
   
Comments
[no name] 10-Jan-12 23:29pm
   
Thanks, that article seemed to confirm my suspicions, I thought it was a bit redundant to have another layer of IDisposable.
Abhinav S 10-Jan-12 23:30pm
   
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900