AddCleanup has been added to the runtime (#67535). We should use runtime.AddCleanup instead of runtime.SetFinalizer in the standard library wherever it is possible.
Remaining instances of SetFinalizer (outside of runtime): - [x] crypto/internal/boring: no longer supported. No use in updating. - [x] crypto/tls: CL 664275 - [x] go/parser/testdata: test only change. Not worth modifying. - [x] internal/types/testdata/check: test only change. Not worth modifying. - [x] internal/poll: CL 671441 - [x] net: CL 638557 adds TODOs - [x] os/exec (Current code relies on object resurrection) - [x] reflect: test only change. Made easy modifications where possible CL 667595 - [x] syscall/js (Current code relies on object resurrection) - [x] weak (intentionally used in test)
@mknyszek
Comment From: gabyhelp
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: gopherbot
Change https://go.dev/cl/638555 mentions this issue: os: use AddCleanup to close files
Comment From: gopherbot
Change https://go.dev/cl/638557 mentions this issue: net: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/638556 mentions this issue: io: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/638578 mentions this issue: os: simplify process status
Comment From: gopherbot
Change https://go.dev/cl/638576 mentions this issue: os: remove Process.mode field
Comment From: gopherbot
Change https://go.dev/cl/638579 mentions this issue: os: use AddCleanup, not SetFinalizer, for Process
Comment From: gopherbot
Change https://go.dev/cl/638575 mentions this issue: os: separate Process.handle into a separate memory allocation
Comment From: gopherbot
Change https://go.dev/cl/638577 mentions this issue: os: don't store reference count in Process.state
Comment From: gopherbot
Change https://go.dev/cl/640735 mentions this issue: sync: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/640736 mentions this issue: cmd/go: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/648655 mentions this issue: net/http: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/649459 mentions this issue: weak: test the use of runtime.AddCleanup
Comment From: gopherbot
Change https://go.dev/cl/649458 mentions this issue: unique: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/664275 mentions this issue: crypto/tls: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/667555 mentions this issue: internal/poll: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/667595 mentions this issue: reflect: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/671441 mentions this issue: internal/poll: use runtime.AddCleanup instead of runtime.SetFinalizer
Comment From: gopherbot
Change https://go.dev/cl/688435 mentions this issue: os: revert the use of AddCleanup to close files and roots