Solved by ptrblck in post #2 
              
              
                a will be freed automatically, if no reference points to this variable. 
Note that PyTorch uses a memory caching mechanism, so nvidia-smi will show all allocated and cached memory as well as the memory used by the CUDA context. 
Here is a small example to demonstrate this behavior: 
# Should be empt…