I think the most efficient way is to do a .clone() of the temporary Tensor after you created it. This will return a new Tensor with its own memory and it will work just fine after the original vector goes out of scope.