Destruction and __del__
Clean up when a value's life ends.
Every Value Has an End
When a value is no longer needed, its life ends and Mojo destroys it. This is your chance to clean up what it owned. 🧹
The Destructor Method
Mojo calls a special method named __del__ to destroy a value. It runs automatically when the value goes out of scope.
fn __del__(owned self):
passAll lessons in this course
- Copy vs Move Semantics
- The __copyinit__ Method
- The __moveinit__ Method
- Destruction and __del__