-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Milestone
Description
The following benchmark consumes unlimited amount of memory:
func BenchmarkSyncLeak(b *testing.B) {
const (
G = 1000
S = 1000
H = 10
)
var wg sync.WaitGroup
wg.Add(G)
for g := 0; g < G; g++ {
go func() {
defer wg.Done()
hold := make([][]uint32, H)
for i := 0; i < b.N; i++ {
a := make([]uint32, S)
atomic.AddUint32(&a[rand.Intn(len(a))], 1)
hold[rand.Intn(len(hold))] = a
}
_ = hold
}()
}
wg.Wait()
}The main cause is that race runtime does not wipe stale synchronization objects from heap memory blocks.