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

Cross page posting, What is cross page posting? By default, the button ...

What is cross page posting? By default, the button controls in the ASP.NET pages post back to the similar page that contains button, where you can write an event handler for th

Seeking somebody to develop a web-based registration screen, Classic ASP ...

Classic ASP I am seeking somebody to develop a web-based user registration screen (List, New, Modify and Delete) preferably using classic ASP framework. The coding must be st

In what order global.asax are triggered?, They are triggered in the followi...

They are triggered in the following order as shown below: Application_BeginRequest Application_AuthenticateRequest Application_AuthorizeRequest Application_ResolveReque

Inheritance, Assignment for inheritance based on c#

Assignment for inheritance based on c#

I want c# api''s as a web service, Project Description: I have a basic C...

Project Description: I have a basic C# control interface that I want to be accessed remotely. Possible implementation using wrappers. Skills required are C# Programming, Webs

Explain windows authentication schemes, Explain Windows authentication Sche...

Explain Windows authentication Schemes There are four parts of windows authentication I. Integrated Windows authentication II. Basic and basic with SSL authentication

Find out circumference and area of a circle – c# program, Find out circumfe...

Find out circumference and area of a circle - C# Program Need Help in Assignment.

How do you implement server-side include directives, Question: (a) How...

Question: (a) How do you implement the following in ASP.NET: (i) Server-side Comments (ii) Server-side Include Directives. (b) (i) Give two reasons why the IsPostBack

Visual basic, how do I load txt file into listbox

how do I load txt file into listbox

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