difference between destructor and garbage collector

后端 未结 4 583
执念已碎
执念已碎 2020-12-31 19:18

I want to know is there any difference between destructor and garbage collector, destructor is used to dispose of all unused objects at the end of the lifetime of the applic

4条回答
  •  情深已故
    2020-12-31 19:36

    The garbage collector is a part of the .NET environment that keeps track of objects and makes sure that objects are removed from memory when they are no longer needed.

    A destructor is a part of a class design. It's the opposite of a constructor. When you declare it the GC will call it when it destroys an object.

    Here is the MSDN documentation.

提交回复
热议问题