I heard many times that as soon as a C # managed program requests more memory from the OS, it will not free it if the system does not have enough memory. For instance. when an object is collected, it is deleted, and the memory occupied by the object can be reused by another managed object, but the memory itself does not return to the operating system (for example, mono on unix will not call brk / sbrk to reduce the amount of virtual memory available to the process , to what was before its allocation).
I donβt know whether this is really happening or not, but I see that my C # applications running on Linux use a small amount of memory at the start, and then when I do something expensive, it allocates more, but later. when all objects are deleted (I can verify that by placing a debug message in destructors), memory is not free. On the other hand, memory is no longer allocated when the memory is restarted. The program simply continues to consume the same amount of memory until it stops.
Perhaps this is just my misunderstanding of how GC in.net works, but if it is, then why? What is the advantage of saving the allocated memory for later rather than returning it back to the system? How can he even know if the system is needed back or not? What about another application that might crash or might not start due to the OOM caused by this effect?
I know that people will probably answer something like "GC manages memory better than you ever could, just don't care about it" or "GC knows what it does best" or "it doesn't have any values, it's just virtual memory ", but it matters, but on my 2gb laptop I launch OOM (and the OOM killer kernel starts because of this) very often when I launch any C # applications after a while from - for this irresponsible memory management.
Note. I tested it all on mono on Linux because it is really difficult for me to understand how windows manage memory, so debugging on Linux is much easier for me, and Linux memory management is the source code, Windows / .Net kernel memory management is pretty for me a riddle
source share