rahul jaiswal

rahul jaiswal

  • NA
  • 177
  • 130.7k

what is difference between destruct or and Garbage Collection?

Aug 25 2012 4:02 AM

1.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.

2.The destruct or is a special member function which is invoked when an object is destroyed. It is the last method run by a class.

The garbage collector is part of the framework, automatically manages memory, and non-deterministically collects unreferenced objects to avoid memory leaks.

3.Both are used to destroy unallocated object in the memory.

4. Destroy are called CLR (Common Language Run time) and Garbage Collection called by .net Framework.


Answers (1)