blob: 772153fd593413763d1ba7ede0081326c296f420 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[[Rust]]
[[When heap data is deallocated]]
[[Moved heap data principle]]
[[Creating a reference to a variable is called borrowing]]
---
When we assign a Box to a name we say that name owns the box. Any time we copy the *pointer* to that box to another name we also pass ownership to that name.
After we pass ownership and move into a new scope the original variable is freed. Thus when we return to the original scope it is no longer possible to use it.
[[Passing a pointer to heap data as an argument to a function transfers its ownership]]
![[Pasted image 20250804184242.png]]
> Wherever the stack variable is greyed out means it is no longer the owner.
|