0Pricing
Mojo Academy · Lesson

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):
    pass

All lessons in this course

  1. Copy vs Move Semantics
  2. The __copyinit__ Method
  3. The __moveinit__ Method
  4. Destruction and __del__
← Back to Mojo Academy