The defer statement in Go actually comes in three flavors: open-coded, heap-allocated, and stack-allocated. Each has its own performance quirks and use cases.
Go EP14: Heap-allocated Defer, Stack-allocated Defer, Open-coded Defer
Go EP14: Heap-allocated Defer…
Go EP14: Heap-allocated Defer, Stack-allocated Defer, Open-coded Defer
The defer statement in Go actually comes in three flavors: open-coded, heap-allocated, and stack-allocated. Each has its own performance quirks and use cases.