Garbage Collector

  • Thread starter Thread starter Elik
  • Start date Start date
E

Elik

Hello
i want to activate the garbage collection when the app
enter to IDLE.
how it can be done, i know how control the GC , but how
can i determine the
idle time.
thanks
 
Hi,

why do you want to do that? It's exactly what the GC is doing anyway?

However you can look at the Application.Idle Event for the purpose of
detecting when your application enteres the idle state.

I would strongly advise you not to call the GC from there.

Hope it helps,

Neno Loje
Microsoft Student Partner
University of Hamburg
 
Thanks Neno

as i understand the GC activated only when the App failed
in memory allocation , not every idle.
i allocated a lot of information from sql server, make
some reports and read another huge block of data etc,
i assumed that if i call the GC everi idle, it will
improved performance.
am i right?
Elik
 
Elik,
i assumed that if i call the GC everi idle, it will
improved performance.
My understanding it will HURT performance, as the GC knows how to take care
of it self, if you start messing with it, it starts making bad choices...
i allocated a lot of information from sql server, make
some reports and read another huge block of data etc,
I would consider calling GC.Collect when I was done with the report and
dereferenced all the objects dealing with the report.

The following articles describe the GC in great detail.
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/

Hope this helps
Jay
 
The GC runs when system resources are low. For most applications, it's best
not to invoke the GC. In addition, if you invoke the GC from your code, you
will make it operate in the same thread as your application. Normally, it
works in its own thread.

You can actually, decrease the performance of your app by calling the GC.

Instead, you should focus on writing "clean" code that uses resources
efficiently.
 
Back
Top