【请教】运行时如何知道应该 deallocate 哪个变量?

💡 原文中文,约300字,阅读约需1分钟。
📝

内容提要

编译期间的 ownership 规则可以避免 double free,而在函数结束时,可以简单地针对重复指针只做一次 deallocate。

🎯

关键要点

  • 编译期间的 ownership 规则可以避免 double free。
  • 在函数结束时,运行时需要知道应该 deallocate 哪个变量。
  • ownership 规则保证所有权 move 之后,不能再访问原变量。
  • 可以简单地针对重复指针只做一次 deallocate。
➡️

继续阅读