Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

what's the difference between  dispose() and GC.collect()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George Shui - 24 Jul 2006 01:54 GMT
I use webBrowser to open a Word document,
when I use  this.webBrowser.dispose(), the WinWord Process end.
while I use  this.webBrowser = null, GC.Collect() , the WinWord Process
still alive.
I want to ask what's the difference between these two function.
Göran Andersson - 25 Jul 2006 20:41 GMT
The Dispose method is used to tell the object to free any unmanaged
resources that it uses. Once this is done, the object only contains
managed resources, and can be handled by the garbage collector once the
reference to the object is removed.

The Dispose method only tells the object to free resources, it doesn't
remove the object itself. The object will be removed when the garbage
collector finds it convenient.

If you don't call Dispose before removing the reference to the object,
two things can happen when the object is to be collected:

:: If the object has a finalizer, the garbage collector will try to use
that to tell the object to free the resources. The object will be
collected at earliest by the next garbage collection.

:: If the object doesn't have a finalizer, it will be collected and the
unmanaged resources will not be freed.

Generally the garbage collector should be left alone. It will free
memory when it's needed, and forcing a collection is not a good way to
try to free unmanaged resources.

> I use webBrowser to open a Word document,
> when I use  this.webBrowser.dispose(), the WinWord Process end.
> while I use  this.webBrowser = null, GC.Collect() , the WinWord Process
> still alive.
> I want to ask what's the difference between these two function.
Nitin Mittal - 27 Jul 2006 09:44 GMT
Hi George

calling a Dispose method on a object frees up the any resources held the
object. It can be called on the objects of classes which implemets
IDisposable interface.

Garbage Collector only fress memory if there are other applicatins which
require more memory. If there is plenty of memory available it will not free
memory.

Regards,
Nitin Mittal

> I use webBrowser to open a Word document,
> when I use  this.webBrowser.dispose(), the WinWord Process end.
> while I use  this.webBrowser = null, GC.Collect() , the WinWord Process
> still alive.
> I want to ask what's the difference between these two function.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.