Proper way to release resources with defer in a loop?
Execution of a deferred function is not only delayed, deferred to the moment the surrounding function returns, it is also executed even if the enclosing function terminates abruptly, e.g. panics. Spec: Defer statements: A “defer” statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function … Read more