Why is it preferred to not use finalize for clean up, DOT NET Programming

The Problem with finalize is that the garbage collection has to make 2  rounds in order to remove the  objects which have finalize methods.

The figure below will make things clear regarding the two rounds of garbage collection rounds performed for the objects having finalized methods.

In this scenario there are 3 objects Object1, Object2 and Object3. The Object2 has the finalize method overridden and remaining objects do not have the finalize method overridden.

Later  when garbage collector runs for the first time it searches for the objects whose memory has to free. He can see 3 objects but it only cleans the memory for Object1 and Object3.The Object2 it pushes to the finalization queue.

Now garbage collector runs for the second time. He views that  there are no objects to be released and then checks for the finalization queue and at this moment it clears object2 from the memory.

So if you notice that object2 was released from memory in the second round and not first. That's why the best method is not to write clean up Non.NET resources in Finalize method rather use the DISPOSE.

 

2474_Finalize.png

Posted Date: 9/22/2012 3:22:06 AM | Location : United States







Related Discussions:- Why is it preferred to not use finalize for clean up, Assignment Help, Ask Question on Why is it preferred to not use finalize for clean up, Get Answer, Expert's Help, Why is it preferred to not use finalize for clean up Discussions

Write discussion on Why is it preferred to not use finalize for clean up
Your posts are moderated
Related Questions
The only difference is that I need the most new version. Things have changed a little since then (the key has), so I need this done freshly. I require the result in C#, sourceco

What is UDDI? The Full form of the UDDI is Universal Description, Discovery and Integration. The directory that can be used to publish and discover public Web Services. If you

I need .net expert help for Advance Project First let me start by saying that I have been writing code for almost 25 years. Therefore I am only looking for someone to aid advanc

What is a Cloud Service? A cloud service is used to build cloud applications. This service gives the facility of using the cloud application without installing it on the comput

What is Array List? An Array is whose size can increase or decrease dynamically. The Array list can hold item of various types. As Array list can increase and decrease his size

Simple FB Integration in MS-SQL and ASP.NET I am seeking urgent project to be done, please I am interested in someone who will present demo for retrieving personal informatio

What is basic use of "DataView"? The "DataView" represents the whole table or can be small parts of rows depending on some criteria. It is the best used for sorting and finding

What are ASP.NET session and compare it with classic ASP session The ASP.NET session caches per user session state. It basically uses "HttpSessionState" class. The limitatio

how make the google sign up page?

A few changes to OutloProject Description: We require someone who is familiar with programming plug-in to work with Microsoft Outlook. Initially we just require a simple chan