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 1.9k
Note: this issue affect GPU and CPU memory.
Alberto