Force memory release to the OS

前端 未结 2 821
傲寒
傲寒 2020-12-21 11:13

I have an app that takes about 20 MB of ram. In an seldom used algorithm it (std::vector) temporarily allocates 250 MB. After the deallocation the systemmonitor still shows

2条回答
  •  孤城傲影
    2020-12-21 11:25

    You can't, and shouldn't.

    Virtual memory allocation is complicated, and cannot be sufficiently understood by simply watching a number in System Monitor. It may appear as if a process is using more memory than it should, but this is just an artefact of the way virtual memory addressing works.

    Rest assured, if you have freed this memory properly, and the OS really needed it back, it would be reassigned.

    The only real actionable point here is to stop using System Monitor as if it were an accurate measure of physical RAM in use by your process!

提交回复
热议问题