Makes sense. When it does not have its own loss function the memory ‘resized’ uses is not being deleted properly so we have memory tied up to a variable that we do not need.
Putting that piece of code in a function will ensure that ‘resized’ memory is freed after it leaves scope and allow us more memory in sequential steps.
Within TensorFlow (v1 so no eager execution), we have a session and a static graph so ‘d’ will leave scope on its own as data flows through the graph.