Showing posts with label C# and ASP.NET Interview Question and Answers. Show all posts
Showing posts with label C# and ASP.NET Interview Question and Answers. Show all posts

Sunday, August 25, 2013

C# and ASP.NET Interview Question and Answers

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 provides Object.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 with finalize 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.