Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are win32File objects truly closed on garbage collection? #308

Open
JackMordaunt opened this issue Dec 11, 2023 · 0 comments
Open

Are win32File objects truly closed on garbage collection? #308

JackMordaunt opened this issue Dec 11, 2023 · 0 comments

Comments

@JackMordaunt
Copy link

The doc comment for win32File indicates the file will be closed when the Go object is garbage collected.

// win32File implements Reader, Writer, and Closer on a Win32 handle without blocking in a syscall.
// It takes ownership of this handle and will close it if it is garbage collected.
type win32File struct {
	handle        windows.Handle
	wg            sync.WaitGroup
	wgLock        sync.RWMutex
	closing       atomicBool
	socket        bool
	readDeadline  deadlineHandler
	writeDeadline deadlineHandler
}

However, grepping through the codebase I cannot find a single call to runtime.SetFinalizer. I'm curious: if this doc comment is true, how is the file being closed on garbage collection without any such calls to runtime.SetFinalizer?

I'm writing some logic that serves net.Conn (provided by this package), and I want to know if I need to take care of setting a finalizer myself or not.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant