📝 You have defined a destructor but it never executed. Why?



The runtime environment automatically invokes the destructor of a class to release the resources that are occupied by variables and methods of an object.



However, in C#, programmers cannot control the timing for invoking destructors, as Garbage Collector is only responsible for releasing the resources used by an object.



Garbage Collector automatically gets information about unreferenced objects from .NET's runtime environment and then invokes the Finalize() method.



Although, it is not preferable to force Garbage Collector to perform garbage collection and retrieve all inaccessible memory (programmers can use the Collect() method of the Garbage Collector class to forcefully execute Garbage Collector).



Take notice that the destructor doesn't (and can't) have a public modifier in-front of it, it's sort of an hint that you can't explicitly call the destructor of an object.



#post