You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[This would be nice to fix for Go 1.7 but is not a regression from Go 1.6 and so is not critical.]
During a range loop on a channel, it appears that the previously received value is held live while blocked waiting for the next value on the channel. The program below demonstrates: f1 retains x even after it is cleared during the loop, while f2 does not. Adjusting the program to block on the channel and then check the memory usage after a suitable timeout produces the same result (but requires sleeps and the like). This matters if the values being received are large and timely garbage collection is important.
This could be fixed by mucking with the liveness code, but it could also be fixed by zeroing the channel receive temporary in the code generated by the range loop after copying it into the real iteration variable. The latter is much less scary at this point in the cycle.
[This would be nice to fix for Go 1.7 but is not a regression from Go 1.6 and so is not critical.]
During a range loop on a channel, it appears that the previously received value is held live while blocked waiting for the next value on the channel. The program below demonstrates: f1 retains x even after it is cleared during the loop, while f2 does not. Adjusting the program to block on the channel and then check the memory usage after a suitable timeout produces the same result (but requires sleeps and the like). This matters if the values being received are large and timely garbage collection is important.
This could be fixed by mucking with the liveness code, but it could also be fixed by zeroing the channel receive temporary in the code generated by the range loop after copying it into the real iteration variable. The latter is much less scary at this point in the cycle.
/cc @randall77 @dr2chase @RLH @aclements
The text was updated successfully, but these errors were encountered: