There is nothing magical about the Dispose method, like any other method. Calling the Dispose method does not perform any cleanup in the background or does not change the state of the object; it simply does what you put in the method. The peculiarity of this is that it is defined in the IDisposable interface, so it is a standard way to report an object in order to clear its resources.
In the Dispose method, the object must take care of all unmanaged resources, such as database connections and Font objects.
When you free an object, you do not need to worry about any managed resources. A structure like an array of bytes is completely handled by the garbage collector, and you can just leave it in the object when you release it. You do not need to set null references, if you no longer use the object, the garbage collector will find the best time to delete it and any objects to which it refers.
The garbage collector usually works best when you leave it alone; there is no need to tell it when it should collect an unused object. He alone will figure out when to do this, and usually it does it better than you, because he has access to a lot of information about the state of memory and the state of the machine that your code does not have.
You may feel that you should try to maintain low memory usage, but there is no advantage. The computer does not work better because it has more free memory. On the contrary, if your code tries to perform a cleanup or causes the garbage collector to perform any operations, it performs the cleanup when it needs to do something more important. The garbage collector will clean an unused object, if necessary.
Guffa
source share