I want to clear any old connection objects left in user's PC as soon as the Home Page of my application starts. Is it safe to run
GC.Collect() as application loads?
It won't hurt anything no, but the garbage collector won't release those objects unless they are properly disposed of first. If they are still in use the collector will pass over them as being active and in use.
In fact you can also try to use "using……" statement to a class instance that has implemented the interface of "IDisposible",which will release the inner unmanaged things together。
rpk2006
Member
631 Points
631 Posts
How to destroy any old connection object when application starts?
Feb 24, 2012 04:11 PM|LINK
I want to clear any old connection objects left in user's PC as soon as the Home Page of my application starts. Is it safe to run GC.Collect() as application loads?
N_EvilScott
Star
8303 Points
1488 Posts
Re: How to destroy any old connection object when application starts?
Feb 24, 2012 06:22 PM|LINK
It won't hurt anything no, but the garbage collector won't release those objects unless they are properly disposed of first. If they are still in use the collector will pass over them as being active and in use.
rpk2006
Member
631 Points
631 Posts
Re: How to destroy any old connection object when application starts?
Feb 25, 2012 05:04 AM|LINK
In that case, I added: connection.dispose in the finally section after the connection got closed?
N_EvilScott
Star
8303 Points
1488 Posts
Re: How to destroy any old connection object when application starts?
Feb 25, 2012 09:02 AM|LINK
You can do that yeah
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to destroy any old connection object when application starts?
Feb 25, 2012 11:33 PM|LINK
Hello rpk2006:)
In fact you can also try to use "using……" statement to a class instance that has implemented the interface of "IDisposible",which will release the inner unmanaged things together。
Reguards!