The default allocator on Linux has a tendency to free unused memory less aggressively than Mac and Windows.
This creates the appearance of memory bloat.
Calling malloc_trim(0)
may not prevent out of memory events of that single process, but it helps you see the real memory usage, and frees up memory for use by other processes.
Relevant links:
- https://old.reddit.com/r/rust/comments/iu8aj3/possible_memory_leak_in_linux_binaries/
- https://www.algolia.com/blog/engineering/when-allocators-are-hoarding-your-precious-memory/
- https://www.youtube.com/watch?v=YB6LTaGRQJg
- https://stackoverflow.com/questions/28612438/can-malloc-trim-release-memory-from-the-middle-of-the-heap