| Author: R.Sujaa 10 Aug 2008 | Member Level: Silver | Rating: Points: 6 |
differences
Finalize:
.NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources (ex: - Windows API created objects, File, Database connection objects, COM objects etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Object.Finalize method which can be overridden and clean up code for unmanaged resources can be put in this
Dispose:
This is the best way we do clean our unallocated resources and yes not to forget we do not get the hit of running the Garbage collector twice.
Collect:
System.GC.Collect() forces garbage collector to run.This is not recommended but can be used if situations arises.
|
| Author: R.Sujaa 10 Aug 2008 | Member Level: Silver | Rating: Points: 5 |
The .NET object does this:
GC.Collect(GC.MaxGeneration);
GC.WaitForPendingFinalizers();
GC.Collect(GC.MaxGeneration);
With the 1.1 framework, the above approach was sufficient to cause any RCWs created for a .NET client that were no longer referenced explicitly in the .NET client code to be collected. That in turn allowed the RCWs to release my COM objects.
Now with 2.0, this no longer seems to work reliably.
|
| Author: chandramohan 11 Aug 2008 | Member Level: Gold | Rating: Points: 0 |
Finalize:
.NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources (ex: - Windows API created objects, File, Database connection objects, COM objects etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Object.Finalize method which can be overridden and clean up code for unmanaged resources can be put in this
Dispose:
This is the best way we do clean our unallocated resources and yes not to forget we do not get the hit of running the Garbage collector twice.
Collect:
System.GC.Collect() forces garbage collector to run.This is not recommended but can be used if situations arises.
|
| Author: Sareesh.V 11 Aug 2008 | Member Level: Silver | Rating: Points: 3 |
Finalize:
.NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources (ex: - Windows API created objects, File, Database connection objects, COM objects etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Object.Finalize method which can be overridden and clean up code for unmanaged resources can be put in this
Dispose:
This is the best way we do clean our unallocated resources and yes not to forget we do not get the hit of running the Garbage collector twice.
Collect:
System.GC.Collect() forces garbage collector to run.This is not recommended but can be used if situations arises.
|
| Author: Bunty 21 Sep 2008 | Member Level: Diamond | Rating: Points: 6 |
Hi,
Following the difference between Dispose and Finalize method,
1>CLR uses the Dispose and Finalize methods for performing garbage collection of runtime objects of .Net applications.
2>Clr has a Garbage Collector(GC) which periodically checks for unused and unreferenced objects in Heap.It call Finalize() method to free the memory used by such objects.
3>Dispose is another method which is invoked by Garbage Collector to release the memory occupied by an object.Dispose method needs to be explicitly called in code for removing an object from Heap.
4>Dispose method can be invoked only by the classes that IDisposable interface.
Regards S.S.Bajoria
Thanks & Regards S.S.Bajoria
|