Interview Questions

How do destructors and garbage collection work in C#?

C# Interview Questions and Answers


(Continued from previous question...)

138. How do destructors and garbage collection work in C#?

C# has finalizers (similar to destructors except that the runtime doesn't guarantee they'll be called), and they are specified as follows:
class C
{
~C()
{
// your code
}
public static void Main() {}
}
Currently, they override object.Finalize(), which is called during the GC process.

(Continued on next question...)

Other Interview Questions