The only thing .detach() does is return a new Tensor without gradient history.
But if in one line you create the result then detach it. The result that was tracking history goes out of scope. And so this part of the history is not referenced by anything and is deleted.