My out of memory problem has been solved. Please check

  
    
    
    CUDA memory continuously increases when net(images) called in every iteration 
  
  
    Hi, I have a very strange error, whereby, when I get by outputs = net(images) within every iteration in a for loop, the CUDA memory usage keeps on increasing, until the GPU runs out of memory. 
The weird situation is that if I have this loop inside a function, it causes this issue. If I just have the contents of the function sitting in my normal script, it works just fine. What may be the cause of this?? 
Thanks