This would actually be the same in python. If you create an object in the middle of the line. It will be gone by the end of it if you don’t reference it.
Here you create a Tensor when doing my_tensor.cpu() (let’s call it foo). Then this object is used to call .data_ptr<float>() on it. The the result of that new function (a float* ) is saved into your variable my_tensor_ptr. At this point, nothing references foo anymore. So foo is de-allocated.