Force memory release to the OS

前端 未结 2 809
傲寒
傲寒 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:45

    Use mmap() or VirtualAlloc() to allocate and release memory. This returns it to the OS immediately.

    In order to use with std::vector, you'll need to provide it a std::allocator. You might find it easier to hand-roll your own vector w/ placement new and direct destructor invocation.

    Normally the system heap allocators handle this correctly for you; however it looks like you found a case where they do not.

提交回复
热议问题