view this thread
http://dotnetspider.com/forum/164800-Difference-between-dispose-gc-collect.aspx
Why chandramohan and sareesh are copying the answer from sujaa...
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: 6 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: 6 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: rajesh 12 Aug 2008 | Member Level: Silver | Rating: Points: 3 |
Yes, UmaShankar is correct..Both of them had copied the answer from Sujaa's thread. Instaed of coping like this give different answers.It vl be easy to understand.
|
| Author: Danasegarane.A 12 Aug 2008 | Member Level: Diamond | Rating: Points: 0 |
They may also refer the Link
:)
|