summaryrefslogtreecommitdiff
path: root/Boxes live in the heap.md
blob: ec296c963a4ac3a3e050e4e509bf2269176e1d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[[Rust]]
[[Variables lives in the stack]]
[[When boxes are deallocated]]
[[Ownership]]

---

The heap is where data can live indefinitely and we can create pointers to it on the stack using a Box.

```rust
let a = Box::new([0; 1_000_000]);
let b = a;
```

Creates an array with 1 million entries on the heap and two variables on the stack that point to it.