Quite commonly an advantage, e.g.:
f, err := openFile('...')
if err != nil {
...
}
defer f.Close()
is how it's commonly used. This makes sense because the cleanup lives next to the initialization of the actual thing it's cleaning up. In a way it becomes part of the initialization, itself.Same with locks and release. Now you don't have to scan across the entire function body to make sure your inits and cleanups match up.