Garbage collector is automatic?

2

I noticed that my application was deliberately consuming the memory even after the end of processing, even finalizing everything that was started so I called the GC.Collect(); and the memory was released.

Garbage collector should not be automatic ?, If yes, are there 'things' that it does not collect or can this be an error in my application?     

asked by anonymous 12.05.2017 / 22:46

1 answer

4

It's automatic and what you've done should not be done . The problem is that there was either no memory pressure or you're not releasing the memory as you are thinking.

/ p>

I do not know the method that you used to check, but the fact that it indicates that there is memory compromised with the application does not mean that it is being used, and what happened was to decompile what was not being used, which is something innocuous and there is even a tiny loss in doing so.

The GC acts when it is needed, it knows how to do it very well. In some rare applications it is necessary to control this in a more specific way and it is not an easy task. But at least it is safe unlike unmanaged languages that in addition to being extra difficult, runs risks. The GC only acts when an heap allocation is requested and does not have space in one of the generations.

I can assure you that there was a lot of collection that you did not even notice. You would have to monitor the GC to see the collections that occurred.

You have a API for this .

List of events it generates .

CLR Profiler .

Process Explorer .

    
12.05.2017 / 23:08