how to call destructor in c# manually code example
Example: c# trigger destructor
//You don't call the destructor in .NET The managed heap is handled by the CLR and the CLR only.
//You can however define a destructor to a class, the destructor would be called once the object gets collected by the GC
class Foo
{
public Foo()
{
Console.WriteLine("Constructed");
}
~Foo()
{
Console.WriteLine("Destructed");
}
}
//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.