Перейти к содержимому

How Rust Frees Memory Without a Garbage Collector | Part 3

Step Into

0:00 / 0:00

How Rust Frees Memory Without a Garbage Collector | Part 3

418 просмотров · 5 дн. назад
Step Into
97 подписчиков
418 просмотров · 5 дн. назад
Rust has no garbage collector, and you never call free(). So who gives the memory back? In Part 3 of Rust in the AI era we follow the token counter's String and Vec onto the stack and the heap, watch a move make a variable unusable, read the real compiler error E0382 (use of moved value) line by line, compare Clone with Copy, and see drop run at the closing brace. The idea: every value has exactly one owner, and the compiler knows who owns what. Chapters 00:00 Who frees the memory? 00:36 What a String is: stack and heap 01:10 Two old answers: free() and garbage collectors 01:50 One owner, and drop at the brace 02:27 The move 03:09 Reading error E0382 line by line 04:04 Clone vs Copy 04:51 The ownership tree 05:42 Functions take ownership too Next: how can a function use a value without taking it? Sources: The Rust Programming Language, ch. 4.1 What Is Ownership? https://doc.rust-lang.org/book/ch04-01-wha... ; ch. 8.1 Vectors https://doc.rust-lang.org/book/ch08-01-vec... ; The Rust Reference, Destructors https://doc.rust-lang.org/reference/destru... ; rustc error index E0382 https://doc.rust-lang.org/error_codes/E038... #rust #rustlang #programming