Garbage Ollector is automatic?

Asked

Viewed 146 times

2

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

Then the doubt came to me, the Garbage Collector shouldn’t it be automatic? , If yes, there are 'things' that it does not collect or this may be an error of my application?

1 answer

4


It is automatic and What you did should not be done. The problem is that actually either there was no pressure from memory or you is not releasing memory as you think you are.

I don’t know the method you used to verify, 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 uncompromising what was not being used, what is something innocuous and even there is a tiny loss in doing this.

The GC acts when it’s needed, he knows how to do it very well. In some rare applications it is necessary to control this more specifically and it is not an easy task. But at least it’s safe, unlike unmanaged languages that are not only extremely difficult, but also at risk. GC only acts when an allocation is requested in the heap and has no place in one of the generations.

I can assure you that there was a lot of collection that you didn’t even notice. I would have to monitor the GC to see the collections that took place.

Has a API for this.

List of events it generates.

CLR Profiler.

Process Explorer.

Process Explorer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.