Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Why is it preferred to not use finalize for clean up
Why is it preferred to not use finalize for clean up?
✍: Guest
Problem with finalize is that garbage collection has to make two rounds in order to remove
objects which have finalize methods.
Below figure will make things clear regarding the two rounds of garbage collection rounds
performed for the objects having finalized methods.
In this scenario there are three objects Object1, Object2 and Object3. Object2 has the
finalize method overridden and remaining objects do not have the finalize method
overridden.
Now when garbage collector runs for the first time it searches for objects whose memory
has to free. He can see three objects but only cleans the memory for Object1 and Object3.
Object2 it pushes to the finalization queue.
Now garbage collector runs for the second time. He see’s 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 practice is not to write clean up Non.NET resources in Finalize
method rather use the DISPOSE.
2007-10-23, 6843👍, 0💬
Popular Posts:
How To Empty Your Recycle Bin? - Oracle DBA FAQ - Managing Oracle Database Tables If your recycle bi...
How To Create an Add-to-My-Yahoo Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...
What is CMM and different levels? explain? The Capability Maturity Model (CMM) is a process capabili...
How To Remove the Top White Space of Your Web Page? - CSS Tutorials - Introduction To CSS Basics The...
How do I use a scriptlet to initialize a newly instantiated bean? A jsp:useBean action may optionall...