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

What is code access security, What is code access security (CAS)? Code ...

What is code access security (CAS)? Code access security (CAS) is part of the .NET security model that stops unauthorized access of resources and operations, and restricts the

Develop a hotel booking wholesale system, Develop a Hotel Booking Wholesale...

Develop a Hotel Booking Wholesale System Project Description: This project is about to prepare a hotel wholesale system for B2B offering travel agents and affiliate websites

What is asp.net ajax, What is ASP.NET AJAX? ASP.NET AJAX, mostly called...

What is ASP.NET AJAX? ASP.NET AJAX, mostly called AJAX, is a set of extensions of ASP.NET. It is developed by Microsoft to execute AJAX functionalities in Web applications. ASP

What is serialization, What is serialization, how it works in .NET? Ser...

What is serialization, how it works in .NET? Serialization is when you persist the state of an object to a storage medium so an exact copy can be re-created at a later stage. S

I need a custom project - c# developer, Project Description: My project ...

Project Description: My project is to construct for me an application that emulates the http requests made in a webapp. It will need a lot of dedication and skill in C#,.net,

Acid fundamental and transactions in sql server, What is ACID fundamental? ...

What is ACID fundamental? What are transactions in SQL SERVER? The transaction is a sequence of operations performed as a single logical unit of work..The logical unit of work

Describe how a user control is declared in an asp.net page, Question: (...

Question: (a) One problem encountered when designing web applications is that HTTP is a "stateless" protocol. Explain two general approaches to solve the statelessness problem

Define importance of vitamin c, Define importance of Vitamin c Freezing...

Define importance of Vitamin c Freezing preserves vegetable and nutrients to a great extent. Vitamin A and β-Carotene are well preserved in spinach, peas and beans, or are mode

I need to develop a real state website, I need to Develop a real state webs...

I need to Develop a real state website We want a programmer who can create a website using html5, css3, jQuery, php, MySQL. All connected to a CRM to accomplish all the informat

Collaboration diagram, Explain the elements of a collaboration diagram. ...

Explain the elements of a collaboration diagram. Classifier Role: - It only classifies a role. Association Role: - It shows the relation b/w two classifier roles.

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