cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
642 stars 100 forks source link

ch04.5 a inappropriate description about GC #185

Open CybCom opened 7 months ago

CybCom commented 7 months ago

The description about the second drawback of GC here is not very appropriate. It asked "what are the contents of the document d" might be mutated in the python example, but this mutation is not a direct consequent of GC, but a result of lacking permission checkers, and will also happens in the languages that does not even have a GC, like C or C++.

willcrichton commented 5 months ago

It's a direct consequence of unrestricted aliasing, which happens in nearly every GC'd language. I don't talk about "unrestricted aliasing" because that is less familiar to the general programmer than "garbage collector". I think if someone arrives at your level of understanding to understand the nuances, I'm happy with that, but it's not essential in that part of the text.

CybCom commented 5 months ago

Thanks for your explanation! I've just re-read this paragraph. I suggest to address explicitly that "both GC and Ownership could avoid UB, but why we chose Ownership here is because just using a GC is still unpredictable (still permits unrestricted aliasing)".