2

I'm reading the C# specification but I don't understand this:

A destructor is a member that implements the actions required to destruct an instance of a class.

Is not the GC that makes actions to destroy an object when this began eligible for destroying?

Into the destructor, generally, we put statements that release unmanaged resources so really I don't understand how we can punt statements that destroy the object itself!

Maybe I misinterpreted what does it means?

xdevel2000
  • 20,780
  • 41
  • 129
  • 196
  • 1
    They're commonly referred to as `Finalizers` in `C#` to avoid confusion. Related : http://stackoverflow.com/a/4899622/1870760 – Hatted Rooster Jan 15 '16 at 16:05
  • Destruct != destroy. – CodeCaster Jan 15 '16 at 16:09
  • @CodeCaster, the answers into "Difference between destructor, dispose and finalize method" don't answer my question! My question is not on that difference but on C# explanation on what a destructor do. I don't think my question is a duplicate. – xdevel2000 Jan 15 '16 at 16:18
  • _"explanation on what a destructor do"_ - which is explained pretty well in the duplicate. Your confusion comes from thinking "destruct" (the opposite of construct) means "destroy" (obliterate from memory), which it doesn't. – CodeCaster Jan 15 '16 at 16:20

1 Answers1

0

Destructor don't destroy the object itself. They are called before the object is destroyed by GC. But they are useful if you have to close some network connection, database connection or any other resource opened previously.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
Gean Ribeiro
  • 1,025
  • 2
  • 10
  • 23