07_threads: 03_leak: Leak vector with Vec::leak, not Box::leak (#107)
Some checks failed
CI / build (push) Has been cancelled
CI / formatter (push) Has been cancelled

This commit is contained in:
Evgeniy Filimonov 2024-06-30 18:23:20 +02:00 committed by GitHub
parent de45f8adf2
commit fccad08921
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,12 +27,12 @@ run out and crash with an out-of-memory error.
fn oom_trigger() { fn oom_trigger() {
loop { loop {
let v: Vec<usize> = Vec::with_capacity(1024); let v: Vec<usize> = Vec::with_capacity(1024);
Box::leak(v); v.leak();
} }
} }
``` ```
At the same time, memory leaked via `Box::leak` is not truly forgotten.\ At the same time, memory leaked via `leak` method is not truly forgotten.\
The operating system can map each memory region to the process responsible for it. The operating system can map each memory region to the process responsible for it.
When the process exits, the operating system will reclaim that memory. When the process exits, the operating system will reclaim that memory.