That is a good idea. I tried to delete loss and output, but it had no effect.
The thing is that I don’t know what uses all the memory so I don’t know what to delete.
The issue is similar to this one How to free GPU memory? (and delete memory allocated variables), but there is no solution there.