You don't have to do anything at all. GC works is some object becomes unreachable. This is explained here:
http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[
^].
This also explains why you have been able to access the object. The mere fact that your code had a reference to it makes it impossible to be garbage collected. And why do you think calling
GC.SuppressFinalize(this);
could possibly clean up memory? it does just the opposite… :-)
You should understand that
System.IDisposable
is itself unrelated to garbage collection. I know where you come from: you read about some technique in the documentation to
GC.SuppressFinalize
, which you did not really understand:
http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx[
^].
But who told you that you should use something like that? Here is the simplest and most effective advice: don't touch GC at all.
[EDIT]
Please see my past answers:
Garbage collectotion takes care of all the memory management[
^],
deferring varirable inside the loop can cuase memory leak?[
^],
Best way to get rid of a public static List Causing an Out of Memory[
^],
Memory management in MDI forms[
^],
Memory leak in WPF DataBinding[
^].
Also, pay attention for some interesting examples of using the
using
statements and
System.IDisposeable
in my articles:
Using "using" Statements: DisposalAccumulator[
^],
Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[
^].
It's good to implement
RAII:
http://en.wikipedia.org/wiki/RAII[
^].
Please see this alternative:
Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[
^].
—SA