When I compile this program with rustc -C opt-level=3:
fn main() {}
valgrind shows that this binary allocates and frees nine times:
==443292== HEAP SUMMARY:
==443292== in use at exit: 0 bytes in 0 blocks
==443292== total heap usage: 9 allocs, 9 frees, 2,160 bytes allocated
==443292==
==443292== All heap blocks were freed -- no leaks are possible
If you want to avoid it, there are the #![no_std] and #![no_main] attributes, as well as a lot of annoying but important details that you have to consider for creating bare metal executables. Here's a short list of resources that will help along the way if you are interested in this path: