Skip to content

Commit

Permalink
Set function to nil after running to allow GC
Browse files Browse the repository at this point in the history
Backport upstream fix to syncext package to allow functions and their
transitive allocations to be GC'd after the function is invoked.
  • Loading branch information
pkwarren committed Mar 8, 2024
1 parent ba932dd commit 1774666
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions private/pkg/syncext/syncext.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func OnceValue[T any](f func() T) func() T {
}
}()
result = f()
f = nil
valid = true
}
return func() T {
Expand Down Expand Up @@ -71,6 +72,7 @@ func OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2) {
}
}()
r1, r2 = f()
f = nil
valid = true
}
return func() (T1, T2) {
Expand Down Expand Up @@ -105,6 +107,7 @@ func OnceValues3[T1, T2, T3 any](f func() (T1, T2, T3)) func() (T1, T2, T3) {
}
}()
r1, r2, r3 = f()
f = nil
valid = true
}
return func() (T1, T2, T3) {
Expand Down

0 comments on commit 1774666

Please sign in to comment.