Why does the rust startup routine bloat both stack and heap for apparently no reason?
⚓ Rust 📅 2026-07-14 👤 surdeus 👁️ 3A C programme, as far as I can tell, does not use stack nor heap unless you explicitly put stuff there. The heap is only used if there is an explicit call to malloc/etc within the code you write/link to. It appears that no matter how simple, though, a Rust program always calls malloc and affiliated around nine times. Even the Hello World program makes some malloc calls. See for yourself :
Memory usage summary: heap total: 3404, heap peak: 1616, stack peak: 1072
total calls total memory failed calls
malloc| 6 3188 0
realloc| 2 64 0 (nomove:0, dec:0, free:0)
calloc| 1 152 0
free| 8 2860
Histogram for block sizes:
0-15 1 11% =========================
32-47 2 22% ==================================================
112-127 1 11% =========================
144-159 1 11% =========================
464-479 1 11% =========================
544-559 1 11% =========================
1024-1039 2 22% ==================================================
This is the output memusage generates when it checks the hello world program as in its simplest implementation. I get it that computers are fast and leaks are memory safe but... seriously ? What is that ? Does linking to the standard library force you to have at least one memory leak no matter how cautious you are ? Calls to malloc and friends aren't the fastest and I don't see why the rust startup routine uses so much memory and does so many allocations where a C program can do the exact same without that overhead. Anyone knows why this choice was made ?
3 posts - 3 participants
🏷️ Rust_feed