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();
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!
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
Since AFAIK the Clear() method just calls Dispose, the using block should be enough to ensure that the resources used are released.
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.
If you take a look using Reflector, you'll see that
Clear
just callsDispose
, so there's no need to callClear
in your example.Many of the framework classes offer a
Close
/Clear
/Whatever cover forDispose
to make the usage a little more straightforward.