Skip to content

Commit a33bbf1

Browse files
cuishuangdr2chase
authored andcommitted
weak: fix weak pointer test to correctly iterate over weak pointers after GC
This change fixes a bug in the weak pointer test where the loop was attempting to iterate over a nil slice (bt) instead of the weak pointer slice (wt). After setting bt to nil and running GC, the test should iterate over the weak pointers to verify they've been cleared, not attempt to iterate over the now-nil strong references. Change-Id: Ic0425f59da132257770ed87d1bcea5d2c0a54e07 Reviewed-on: https://go-review.googlesource.com/c/go/+/723600 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Sean Liao <[email protected]>
1 parent a88a963 commit a33bbf1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/weak/pointer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestPointerEquality(t *testing.T) {
110110
bt = nil
111111
// bt is no longer referenced.
112112
runtime.GC()
113-
for i := range bt {
113+
for i := range wt {
114114
st := wt[i].Value()
115115
if st != nil {
116116
t.Fatalf("expected weak pointer to be nil, got %p", st)

0 commit comments

Comments
 (0)