Weak ref change for #668 and #729

Cherry pick 29636904e780ddc946f79475aa58ffaf7abba3e4