When allocating with the new keyword, does the CLR ever throttle via a Sleep statement when memory is low

Bob Bryan 96 Reputation points
2021-08-27T21:10:22.347+00:00

I came across this answer on Stack Overflow:

When you allocate faster than you can garbage collect you will run into OOM. If you do heavy allocations the CLR will insert a Sleep(xx) to throttle allocation but this is not enough in your extreme case.

So, I have not read anything about the CLR throttling allocations by inserting a Sleep statement to slow down allocations when memory is low. Can you confirm if this is true or not? If it is true, then Is there any documentation that talks about the details. I have tried doing Google searches, but could not find anything to support this claim.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,310 questions
{count} votes

Accepted answer
  1. Bob Bryan 96 Reputation points
    2021-09-13T01:25:21.737+00:00

    From my answer on Stack Overflow:

    In conclusion, the answer to the question I posed is yes, the CLR does throttle allocations when a background GC is running. The rationale to throttling allocations appears to be to allow the background GC to complete its job more quickly and efficiently.

    0 comments No comments

0 additional answers

Sort by: Most helpful