Skip to content

Commit

Permalink
Vec::new() doesn't allocate (#2026)
Browse files Browse the repository at this point in the history
So remove it from the list of things to look on that allocate, and
replace with `vec![]`, which does allocate (if given any elements).
  • Loading branch information
ChayimFriedman2 authored Apr 25, 2024
1 parent 402ac3a commit 5633dd5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/memory-management/clone.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
<details>

- The idea of `Clone` is to make it easy to spot where heap allocations are
occurring. Look for `.clone()` and a few others like `Vec::new` or `Box::new`.
occurring. Look for `.clone()` and a few others like `vec!` or `Box::new`.

- It's common to "clone your way out" of problems with the borrow checker, and
return later to try to optimize those clones away.
Expand Down

0 comments on commit 5633dd5

Please sign in to comment.