Solved by bgobbi in post #5 
              
              
                I solved the memory leak. I found the solution in the FAQ: 
https://pytorch.org/docs/stable/notes/faq.html#my-model-reports-cuda-runtime-error-2-out-of-memory 
Note: this issue affect GPU and CPU memory. 
Alberto