views:

267

answers:

5

Hi folks.

I have this code :-

using (System.Security.Cryptography.SHA256 sha2 = 
    new System.Security.Cryptography.SHA256Managed())
{ .. }

Do I need to put this line of code, just BEFORE I leave that dispose scope .. or does the dispose 'call' that already.

sha2.Clear();
+1  A: 

Since AFAIK the Clear() method just calls Dispose, the using block should be enough to ensure that the resources used are released.

cheers! i forgot about reflector, to check that :P
Pure.Krome
+1  A: 

IMHO if calling Dispose() is not enough to dispose off an object then either there is a serious bug in the code or a serious flaw in the design. So don't worry about taking any additional steps in your own code!

SDX2000
A: 

And a generic helpful hint - don't forget at that the source for all this stuff is available nowadays - it often helps me answer this sort of question, without having to guess or infer.

This is a good place to start: http://www.codeplex.com/NetMassDownloader

Will Dean
wtf? what has this to do with my question? ??? ????
Pure.Krome
Well, you could look into the code just like you do with .NET Reflector. Given, that the source for system.security are yet part of the sources being published (I'm not sure).
Christian.K
Not sure why the swearing is in order, even abbreviated. What it has to do with your question is that it's the kind of question that could be answered by looking at the source. Had you been the type of person who wanted to learn about things, that might have been useful. Sorry to have misread you
Will Dean
A: 

Dispose() is good enough.

I am not sure how .NET works. But addition function call or "set null" will degrade the performance in Java.

The CLR/Java VM will(and must) able to cleanup all dereferenced managed object from "roots" in the next garbage collection.

PS. Dispose() does cleanup "unmanaged" resources, to improve the GC performance as it don't wait for the Finallizer thread to complete.

Dennis Cheung
lol. u edited your reply after vote downs :P
Pure.Krome
+1  A: 

If you take a look using Reflector, you'll see that Clear just calls Dispose, so there's no need to call Clear in your example.

Many of the framework classes offer a Close/Clear/Whatever cover for Dispose to make the usage a little more straightforward.

Brian Rasmussen