What is the significance of Finalize method in .NET?
.NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources (example: Windows API created objects, File, Database connection objects, COM objects, etc.) are outside the scope of .NET Framework. We have to explicitly clean our resources. For these types of objects, .NET Framework providesObject.Finalize method, which can be overridden and
clean up code for unmanaged resources can be put in this section?
Why is it preferred to not use finalize for clean up?
The problem withfinalize is that garbage collection has to make two rounds in order to remove
objects which have finalize methods.
The below figure will make things clear regarding the two rounds of garbage collection rounds performed for the objects having finalized methods.