Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it smart to use GC.Collect on application that runs 24h per day?

We have application that runs 24h per day and 7 days per week. Sometimes CPU go to 100% and then go back to 80%. The same with RAM. Is it smart to manually call GC.Collect after few hours or betterto leave it automatically.

We are using C# 2010, SQL 2008 and Fluent Nhiberanet. This is desktop application.

like image 938
senzacionale Avatar asked Jan 23 '12 13:01

senzacionale


People also ask

How does garbage collection impact on application performance?

The most common performance problem associated with Java™ relates to the garbage collection mechanism. If the size of the Java heap is too large, the heap must reside outside main memory. This causes increased paging activity, which affects Java performance. Also, a large heap can take several seconds to fill up.

Should you ever call GC collect?

Refrain from calling the GC. Collect method explicitly to reclaim the memory occupied by the objects in your application unless there is a specific reason do so. The GC. Collect() method has for long been popular among .

When should you not use garbage collection?

One fundamental problem with garbage collection, though, is that it is difficult to estimate and manage the actual size of the working set in memory, because garbage collector can free your memory only delayedly. So, yes, when memory is restricted, garbage collection might not be a good choice.

Is GC collect expensive?

The GC. Collect() is a very expensive method which should be avoided.


1 Answers

I wouldn't call it smart to call GC.Collect() "every few hours", or "when RAM usage goes to high", but I'd call it smart to call it whenever you are in a position of having more information than the GC, some exmaples

  • You know, this big chunk of RAM or these many small objects you just allocated, will not be used again and you are in a singlethreaded environment and (ofcourse) you have cleared all your references
  • You know, that a "GC break" will hurt less right now, than a bit later

The GC is a highly optimized peace of code and quite smart, but it can only work on information it has.

like image 125
Eugen Rieck Avatar answered Oct 11 '22 14:10

Eugen Rieck