The Default Philosophy when OOM
The default behavior is:
Wiki topics:
PHI · Philosophy
The Default Philosophy when OOM
The default behavior is:
- If the binary links against
std(typically the case), then print a message to standard error and abort the process. This behavior can be replaced with[set_alloc_error_hook](https://doc.rust-lang.org/std/alloc/fn.set_alloc_error_hook.html) and[take_alloc_error_hook](https://doc.rust-lang.org/std/alloc/fn.take_alloc_error_hook.html). Future versions of Rust may panic by default instead. - If the binary does not link against
std(all of its crates are marked[#![no_std]](https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute)), then call[panic!](https://doc.rust-lang.org/core/macro.panic.html) with a message. The panic handler applies as to any panic.
Rust’s default memory allocation philosophy is to abort (crash) on OOM, not to attempt recovery. This aligns with Rust’s goals of:
- Safety: No undefined behavior or silent corruption.
- Simplicity: No implicit error handling for allocations that rarely fail in practice.
- Performance: Avoid the cost of checking every allocation for
Result.
So, when an allocation fails (for example, Vec::push() needs to grow and malloc fails), Rust’s standard library calls the global OOM handler, which by default terminates the program (usually via abort()).
메타데이터
- post_id
- 2b06c71ed835
- slug
- the-default-philosophy-when-oom-2b06c71ed835
- url
- https://medium.com/@CyberGee/the-default-philosophy-when-oom-2b06c71ed835
- canonical_url
- https://medium.com/@CyberGee/the-default-philosophy-when-oom-2b06c71ed835
- author_url
- https://medium.com/@CyberGee
- status
- ok
- fetched_at
- 2026-06-12 18:14:10