]> Cypherpunks repositories - gostls13.git/commit
sync: do not unnecessarily keep alive functions wrapped by Once(Func|Value|Values)
authorCarlo Alberto Ferraris <cafxx@strayorange.com>
Sun, 2 Apr 2023 14:54:35 +0000 (23:54 +0900)
committerDavid Chase <drchase@google.com>
Tue, 21 Nov 2023 17:31:33 +0000 (17:31 +0000)
commit4f55a5af5e5d325a534222050564766c249218aa
tree4ae677c6e6b59e36783f61e6fb7bb0fa176b585b
parent5239c913510633ce9fdfaf993ab5f31d7ba7e83e
sync: do not unnecessarily keep alive functions wrapped by Once(Func|Value|Values)

The function passed to OnceFunc/OnceValue/OnceValues may transitively
keep more allocations alive. As the passed function is guaranteed to be
called at most once, it is safe to drop it after the first call is
complete. This avoids keeping the passed function (and anything it
transitively references) alive until the returned function is GCed.

Change-Id: I2faf397b481d2f693ab3aea8e2981b02adbc7a21
Reviewed-on: https://go-review.googlesource.com/c/go/+/481515
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: qiulaidongfeng <2645477756@qq.com>
src/runtime/export_test.go
src/runtime/mfinal.go
src/sync/oncefunc.go
src/sync/oncefunc_test.go