when you call .item() it returns the value of the tensor which is just a number. But in your earlier case you are adding loss which is a reference(not a value of tensor). So, you are holding that the reference to that computational graph every time you are doing total_loss += loss, which otherwise would have been destroyed after the update. To see the difference yourself,
print(loss)
print(loss.item())

print(type(loss))
print(type(loss.item()))


The first prints a tensor which is the graph(as everything is connected) where as the second is just a float.
PS: If your problem is solved mark the above comment as solution so that others may find it helpful.