3 ms·
Then what's the point of the Close method in the File interface (https://pkg.go.dev/io/fs@go1.18.1#File https://pkg.go.dev/io/fs@go1.18.1#File) ?
by eptcyka 5y ago
Then what's the point of the Close method in the File interface (https://pkg.go.dev/io/fs@go1.18.1#File https://pkg.go.dev/io/fs@go1.18.1#File) ?
- woodruffw 5y agoI’m not a Go programmer, but I assume it’s there for the same reason every other GC’d language has the ability to close resources manually: sometimes you just want to do it earlier (or more explicitly) than the GC would.
- Andys 5y ago...You might want to close a handle at any time?
- TheDong 5y agoIt lets you check for errors, and have a deterministic time at which the file is closed. Both of these are desirable properties. The finalizer is there to prevent a subset of resource leaks, not to be relied upon.