r2.15 cherry-pick: f37fad4c3ca "Fix high memory usage when running eager ops as a function."
@learning-to-play Intel wants this to make it into 2.15 to address a memory-leak issue blocking several of their clients.  The corresponding issue is #58676.
Refer to the original commit: https://github.com/tensorflow/tensorflow/commit/f37fad4