tur/typeclass-drop
Drop typeclass for releasing an owned value.
Auto-loaded (like typeclass-clone.tur) so a module can declare (definstance Drop [...] ...) without importing typeclass.tur.
A type implements Drop when it OWNS a resource that must be released when the value dies -- a refcounted handle (decrement), a unique heap pointer (free), a nested owning aggregate (walk). The closure drop-glue (docs/archive/closure-drop-glue-plan.md, Model R) dispatches through a capture's Drop instance to release it when the capturing env is freed, so an owned value captured into an escaping closure no longer leaks.
Drop composes with Clone: a Drop type that is ALSO Clone (e.g. a refcounted String) is RETAINed (via clone) when captured and released (via drop) when the env dies, so the retain/release balances regardless of aliasing. A Drop type that is NOT Clone is move-only: capturing it consumes the source (a second use is a compile-time use-after-move), so the env is its sole owner.
Since: v2 (Model R)
Drop
(defclass Drop [a])
values that own a resource to release when the value dies.
| a | the owning type |
(drop [x] :void)-
release what
xowns -- decrement a refcount, free a unique pointer, walk a nested owner. The closure drop-glue calls it when a capturing env is freed;xis not used afterwards.
Implement Drop only for a type that really owns something. Pair it with Clone for a shareable (refcounted) type; leave Clone off to make the type move-only.
Since: v2 (Model R)