A [[Go]] / [[Zig]] language feature on [[Ownership]] and [[Resource Management]].
`defer` has few nice properties compared to them;
- Does not incur stack or scope or indentation.
- Simpler / explicit than RAII, as with RAII an explicit type with destructor is needed.
- Can be less error than RAII at controlling the destruction behavior as an unexpected leakage of shared pointer can cause resource to outlive its intended scope.
- However, can be more error prone if the the `defer` is omitted, or an invalid object is used after the defer.
# Other Languages
- [[Zig]] has `defer`.
- [[Csharp|C#]]'s `using`, which existed since 1.0 (!!)
- [[TypeScript]] / ECMAScript's `using` - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management.
- Resource blocks in [[Python]] and [[Java]]