Skip to content
TopicTracker
From HackerNewsView original
TranslationTranslation

Rust Service Isn't Leaking – It Could Be the Allocator

The article explains that apparent memory growth in a Rust application may not be a leak but rather a behavior of the default system allocator, which holds onto freed memory for performance. It demonstrates how switching to a different allocator like `mimalloc` can reduce memory usage and shows how to profile allocations to better understand a program's true memory footprint.

Background

Rust's default memory allocator (jemalloc) can appear to leak memory by holding onto freed pages instead of returning them to the OS. This post shows that apparent memory growth in a Rust HTTP service was actually a harmless allocator behavior, not a bug in the application code. Tools like `heaptrack` or `valgrind` can help distinguish real leaks from allocator-level caching. The key insight: a rising RSS (resident set size) doesn't always mean memory is being lost — the allocator may simply be keeping buffers ready for future use.

Related stories