Generally speaking, you should get rid of resources as soon as possible. If you do not need a resource, why would you save it in vain?
In addition, to call Dispose () during finalization, you will need to create a finalizer for your object, that is, a destructor in C #. However, the exact time the object finalizer is called is not deterministic, which means that at this point your managed objects may be inaccessible and inaccessible. Even the thread that your finalizer executes is not deterministic, which can also lead to problems that are difficult to anticipate.
For these reasons, finalizers must be created to free up unmanaged resources.
Very few programmers understand completely how the revision works. For example, the garbage collector recognizes that your type has a finalizer during object creation and places your instance in a special internal data structure called finalizequeue. In fact, when you debug your application using sos.dll (windbg), you can use the command! FinalizeQueue for displaying objects with finalizers and not yet completed at some later point in time.
user3869175
source share