Destructor in C sharp programming language

Why the destructor not executed if we have defined a destructor in the class which we have developed through C# programming language?

E

Expert

Verified

Runtime environment automatically calls up a destructor of the class to release a resource which is occupied by the variables and the methods of the object. But, in C#, programmers cannot control the timing for calling destructors, since Garbage Collector is only in charge for releasing the resources used by the object. Garbage Collector automatically acquires information regarding unreferenced objects from .NET's runtime environment and then calls up the Finalize() method.

Even though, it is not preferable to force Garbage Collector to carry out garbage collection and recover all inaccessible memory, programmers can utilize the Collect() method of a Garbage Collector class to forcefully perform Garbage Collector.

   Related Questions in Software Engineering

©TutorsGlobe All rights reserved 2022-2023.