Garbage collection in C# not carried out. Why?

后端 未结 5 2006
感动是毒
感动是毒 2021-02-12 03:58

I have tried a simple experiment to verify the functionality of the garbage collector. Referencing 3.9 Automatic memory management (MSDN) about automatic memory managem

5条回答
  •  抹茶落季
    2021-02-12 04:39

    Even if it did de-allocate the memory internally, it's under no obligation to return it to the operating system. It will assume that more memory will be requested in the future and recycle the pages. The operating system's number knows nothing of how the program has chosen to use the memory it has claimed.

    If you actually want to claim and release memory explicitly you'll have to call VirtualAlloc() through Pinvoke unsafe code.

提交回复
热议问题