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

Assignment Help:

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


Related Discussions:- Why is it preferred to not use finalize for clean up

Do webservice have state?, Webservices as such do not have any mechanism by...

Webservices as such do not have any mechanism by which they can maintain their state. The Webservices can access ASP.NET intrinsic objects such as application, session and many mor

Pollution software vehicle, Project Description: i want to prepare a pol...

Project Description: i want to prepare a pollution checking software.. i have a demo of it.. Exactly someone to be created ..some changes to be included.. sms gateway t

In which statement the linq query is executed, In which statement the LINQ ...

In which statement the LINQ query is executed? A LINQ query is executed in the For every statement in Visual Basic and in the for each statement in C#.

What is a workflow, What is a workflow? A workflow is a collection of a...

What is a workflow? A workflow is a collection of actions (called activities) that presents the model of a process. A workflow gives a way to explain the order of the execution

Create a xslt and css file, Using the attached XML file (xml_ind.xml) creat...

Using the attached XML file (xml_ind.xml) create a XSLT and CSS file for the following information: select the following information for ONLY the cars that cost more than $50,00

I need export data using json, I need Export Data using JSON Project Des...

I need Export Data using JSON Project Description: We could like to share our data with other websites via JSON. We are presently using Entity Framework with MySQL. We req

What is the difference between dynamic and var data types, What is the diff...

What is the difference between dynamic and var data types? The difference among the var and dynamic data types is that the var data type is strongly type checked at the compile

Why project needed xml?, Explain why your project needed XML. Remember ...

Explain why your project needed XML. Remember XML was meant to exchange data between the two entities as you can define your user friendly tags with ease. In the real world sce

What is the concept of strong names, concept of strong names Strong nam...

concept of strong names Strong name is similar to GUID(It is supposed to be unique in space and time) in the COM components.Strong Name is only needed when we need to deploy as

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd