On this page
Cleanup and memory ownership๏
Beginner. Cleanup without ceremony.
Declare your teardown vocabulary โ the method names that mean "clean yourself up" in this system โ and Melder calls them on the way down. No base class, no protocol, no context-manager ceremony:
book = md.Spellbook()
book.bind(
spell=PooledConnection,
existence="unique",
disposal_method_names=["close", "shutdown"], # this binding's ordered methods
)
book.bind(
spell=BackgroundWorker,
existence="unique",
disposal_method_names=["shutdown"],
)
conduit = book.conjure()
...
conduit.cleanup() # calls each creation's matched methods in their declared order
Each bind's list belongs to that spell, not every later bind. Melder resolves matching class methods once at bind time and preserves their order:
If the connection implements both names,
close()runs beforeshutdown().The worker uses its own
shutdown()declaration.Missing names are omitted; duplicate names execute once.
For book-wide methods, use SpellbookConfiguration. Its matching methods form
one ordered block: last by default, or first with
with_enforce_priority_disposal_methods(True). Shared names belong to the book's
block in either mode; spell-only names retain their own order. See the
configuration guide
for both arrangements.
Cleanup retains its existing reverse key/bucket traversal within each store. A failing
method stops that object's remaining method calls; cleanup continues with other
objects and aggregates failures into an ExceptionGroup.
Runnable examples๏
Disposal contract โ Beginner 08
Explicit cleanup โ Beginner 10
Disposal multiple methods โ Beginner 35
You own the memory now โ Beginner 41