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

Static chart diagrams, Describe all elements in Static Chart diagrams. ...

Describe all elements in Static Chart diagrams. Package: - The Package logically groups element of a UML model. Class: - The Class describes all set of objects with

Develop skype recorder application, Develop Skype Recorder Application + Se...

Develop Skype Recorder Application + Setup + Sourcecode + NICE UI Project Description: i need an application built which will allow user to record skype audio or video calls

ASP.NET, What is the Append Format for FileUpload Control in ASP.Net? What ...

What is the Append Format for FileUpload Control in ASP.Net? What it specify?

Slide bettween window application, Slide Bettween Window Application 1 P...

Slide Bettween Window Application 1 Project Description: Like Mouse Gesture. Keep Right Mouse, Slide Left and drop right mouse. Move to earlier app on taskbar. Keep Lef

Explain the concept of web services in brief, Explain the concept of Web se...

Explain the concept of Web services in brief. A Web service may be explained as an independent and self-sustained unit of a software application that is hosted on the Web and i

I need a dataflow system, Development Executive of DataFlow System, We s...

Development Executive of DataFlow System, We started by initially providing our customers with customized ITES solutions and IT. We have now expanded our services which add QA s

Program of addition of byte type variables – c# program, Program of additio...

Program of addition of byte type variables - C# Program Program of addition of byte type variables, i need program code for performing addition of byte type variables. Can any

Unity 4 ios pro developer to prepare link.xml, Unity 4 iOS Pro Developer to...

Unity 4 iOS Pro Developer to prepare link.xml Project Description: I'm seeking an iOS developer with a Unity 4 iOS Pro license to prepare a link.xml file that will let my pro

Database, can we use sql data base with visual studio

can we use sql data base with visual studio

Need of static methods for post cache substitution, Why do we need static m...

Why do we need static methods for Post Cache substitution? The ASP.NET should be able to call this static method even when there isn't an instance of your page class available.

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