mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-04 11:39:42 +02:00
Rephrase “No memory leaks”
The footnote was added before we had support for speaker notes. It’s too large to show on the screen during a classroom presentation, so it has now been moved to the speaker notes. I tried to keep the information intact, including keeping the word “mostly” on the slide.
This commit is contained in:
parent
a7adf49002
commit
cf505e99cd
@ -3,7 +3,7 @@
|
||||
Static memory management at compile time:
|
||||
|
||||
* No uninitialized variables.
|
||||
* *Mostly* no memory leaks[^leaks].
|
||||
* No memory leaks (_mostly_, see notes).
|
||||
* No double-frees.
|
||||
* No use-after-free.
|
||||
* No `NULL` pointers.
|
||||
@ -11,4 +11,23 @@ Static memory management at compile time:
|
||||
* No data races between threads.
|
||||
* No iterator invalidation.
|
||||
|
||||
[^leaks]: It is technically possible to produce a memory leak in (safe) Rust. The [`Box::leak`](https://doc.rust-lang.org/std/boxed/struct.Box.html#method.leak) method allows getting a raw reference out of a [`Box`](https://doc.rust-lang.org/std/boxed/struct.Box.html) and dropping the [`Box`](https://doc.rust-lang.org/std/boxed/struct.Box.html) afterwards, without running the destructor. A use of this could be to get runtime-initialized and runtime-sized static variables. Or simply, the [`std::mem::forget`](https://doc.rust-lang.org/std/mem/fn.forget.html) function, which makes the compiler "forget" about a value meaning the destructor is never run. There are many other ways to create leaks in safe Rust, but for the purpose of this course, "No memory leaks" should be understood as "Pretty much no *accidental* memory leaks".
|
||||
<details>
|
||||
|
||||
It is possible to produce memory leaks in (safe) Rust. Some examples
|
||||
are:
|
||||
|
||||
* You can for use [`Box::leak`] to leak a pointer. A use of this could
|
||||
be to get runtime-initialized and runtime-sized static variables
|
||||
* You can use [`std::mem::forget`] to make the compiler "forget" about
|
||||
a value (meaning the destructor is never run).
|
||||
* You can also accidentally create a [reference cycle] with `Rc` or
|
||||
`Arc`.
|
||||
|
||||
For the purpose of this course, "No memory leaks" should be understood
|
||||
as "Pretty much no *accidental* memory leaks".
|
||||
|
||||
[`Box::leak`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.leak
|
||||
[`std::mem::forget`]: https://doc.rust-lang.org/std/mem/fn.forget.html
|
||||
[reference cycle]: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user