Reading through Tess Ferrandez' Blog on garbage collection, she says that there are 3 possible causes for a collection:
- When you allocate a new object and the generation 0 budget is reached, i.e. if the new object would cause it to go over-budget.
- When someone calls GC.Collect (Induced GC)
- Based on memory pressure
I understand points 1 and 2, but what is meant by memory pressure in point 3?
I had assumed it was the general memory available in the system, but if the system really did use up all of its memory then I'd imagine the whole system would blue-screen.
What is actually meant by memory pressure? How does it differ from exceeding a generation's budget?
In point 3, Tess refers to "low memory notification" send by Windows in case of running out of available memory. Applications may listen to that notification - to react somehow before something worse happens (for example, saving its crucial data and so on, so forth). Well-behaving applications may even try to help the OS by trimming their own memory usage.
CLR is listening for low memory notification. When it happens, GC is triggered and generally, it makes GCs more aggressive. The benefits are mutual because reducing the pressure on memory helps all applications in the system (including the .NET app itself).
When exactly low memory notification is sent is not so well documented. According to the comment in the internal System.Runtime.Caching.PhysicalMemoryMonitor
class, that in turn is based on comments from internal Windows implementations, the low memory notification is signaled when about 97-99% of physical memory is occupied (depending on the physical RAM amount installed in the system).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With