PC Review


Reply
 
 
perspolis
Guest
Posts: n/a
 
      21st Dec 2006
Hi all
I want to know how can I force GC to be callled?

thanks in advance


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      21st Dec 2006
GC.Collect();

However, this is not recommended in most scenarios. Normally, just let
the GC do its thing. Do you have a specific reason for wanting to
force this? There may be better options...

Marc


 
Reply With Quote
 
=?Utf-8?B?TWFyayBSLiBEYXdzb24=?=
Guest
Posts: n/a
 
      21st Dec 2006
Hi Perspolis,
you can force the garbage collector to run by calling GC.Collect() which
will force a collection on all generations of eligable objects to be
collected. Generally though you should not have to force the GC since it
knows best when to run, what problem are you trying to solve?

Mark.
--
http://www.markdawson.org


"perspolis" wrote:

> Hi all
> I want to know how can I force GC to be callled?
>
> thanks in advance
>
>
>

 
Reply With Quote
 
perspolis
Guest
Posts: n/a
 
      21st Dec 2006
I have a database application and using pooling in my connection.
In some reasons I want to restore my database (SqlServer).
but because of pooling it give me error "The database is using ";
I have a method that clears SqlConnection pool and place it in destructore.
But when I want tor restore the destructor has no been called yet.

"Marc Gravell" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> GC.Collect();
>
> However, this is not recommended in most scenarios. Normally, just let the
> GC do its thing. Do you have a specific reason for wanting to force this?
> There may be better options...
>
> Marc
>
>



 
Reply With Quote
 
Greg
Guest
Posts: n/a
 
      21st Dec 2006

Marc Gravell wrote:
> GC.Collect();
>
> However, this is not recommended in most scenarios. Normally, just let
> the GC do its thing. Do you have a specific reason for wanting to
> force this? There may be better options...
>
> Marc


Also
GC.WaitForPendingFinalizers();

If you want a synchronous call to wait until all the finalizers are
complete (the collect method is launched in a separate thread)

--------------------------------------------------------------
visit: www.scogico.com

 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      21st Dec 2006
pedant note: finalizer, not destructor

If you want deterministic cleanup of some bespoke object (of yours),
then IDisposable is a much better pattern than a finalizer.
Theoretically you should just have to call ClearAllPools(), and then
ensure that all in-use connections are properly closed (and ideally
disposed). I haven't tried it though. Of course, since you obviously
have elevated privelege at the database (to invoke a restore), you
could also presumably kill the spids from the server.

http://msdn2.microsoft.com/en-us/library/8xx3tyca(VS.80).aspx

Marc


 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      21st Dec 2006
Good catch; in the (undesirable) scenario where you are dependent on a
particular finalizer, then sync rather than async is necessary. But
best to avoid it in the first place (IDisposable etc).

Marc


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio jeeji Microsoft C# .NET 1 29th Jun 2006 10:43 AM
Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function Savvoulidis Iordanis Microsoft Access Form Coding 2 19th Mar 2005 06:34 PM
Fail to send fax when making international fax calling / calling c =?Utf-8?B?c2Ftd2lzZQ==?= Windows XP Help 1 28th Dec 2004 02:31 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= Microsoft ASP .NET 1 28th Sep 2004 01:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier Microsoft ASP .NET 4 29th Jul 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.