microsoft / microsoft/mimalloc
Question about releasing memory
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
Hello,
I'm trying to use mimalloc with my binary. And have questions about memory release to OS.
I have a memory storage, it allocates 300MB of memory.
Then I destroy it.
And expect to return memory back to OS, but instead I see memory is not returned.
Then I init another storage and memory grows by another 300MB.
Compiling mimalloc:
cmake -B cmake-build-dir/release -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17
Compiling my binary with:
/usr/x86_64-linux-musl-cross/lib/mimalloc-1.7/libmimalloc.a
Added to main.cxx:
#include <mimalloc.h>
#include <mimalloc-override.h>
Compiling everything with Release build type.
What I see in process stats:
Started:
elgato 2429 2.0 0.1 272984 8808 pts/3 Sl+ 17:57 0:00 build/linux_x64/lt2http
Storage init:
elgato 2429 1.4 4.0 797568 322636 pts/3 Sl+ 17:57 0:00 build/linux_x64/lt2http
Storage destroyed:
elgato 2429 1.0 4.0 797712 322900 pts/3 Sl+ 17:57 0:00 build/linux_x64/lt2http
Storage re-init:
elgato 2429 1.0 4.7 797712 381244 pts/3 Sl+ 17:57 0:00 build/linux_x64/lt2http
Storage re-destroyed:
elgato 2429 0.8 4.7 797712 381244 pts/3 Sl+ 17:57 0:01 build/linux_x64/lt2http
Stats after closing:
heap stats: peak total freed current unit count
reserved: 768.0 mb 768.0 mb 512.0 mb 256.0 mb 1 b not all freed!
committed: 745.9 mb 745.9 mb 512.0 mb 233.9 mb 1 b not all freed!
reset: 4.2 mb 5.4 mb 1.1 mb 4.2 mb 1 b not all freed!
touched: 0 b 0 b 606.3 mb -606.3 mb 1 b ok
segments: 16 318 314 4 not all freed!
-abandoned: 5 5 5 0 ok
-cached: 0 0 0 0 ok
pages: 300 353 325 28 not all freed!
-abandoned: 30 30 30 0 ok
-extended: 0
-noretire: 0
mmaps: 0
commits: 198
threads: 7 7 12 -5 ok
searches: 0.0 avg
numa nodes: 1
elapsed: 144.618 s
process: user: 0.610 s, system: 0.552 s, faults: 0, rss: 372.6 mb, commit: 745.9 mb
I understand that mimalloc is probably keeping memory for re-use in future.
But is there any configuration, that can be changed to force memory release?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the mimalloc configuration and memory-release behavior described in the issue, using the provided CMake command and mimalloc override setup. Reproduce the storage init, destroy, and re-init sequence, then compare the process statistics and heap stats; done means explaining whether the observed retention is expected and identifying a supported way to release memory, if one exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cmake
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100