In your first example you are replacing the x tensor in each iteration, so that the “old” x tensor can be freed or more specifically: it’s memory can be reused.
PyTorch frees memory of tensors, which don’t have any valid reference pointing to them anymore.
Since y points to the data of x, this data cannot be freed even after x was deleted.