Thank you for the response.
I disabled detect_anomaly and checked the CPU memory usage. I found there had been a memory leaking problem while running this code. However, I found the memory leaking problem maintained even after I disabled detect_anomaly. Below is the result of perfmon (Windows)

perfmon1280×914 29.1 KB

In addition, I found my GPU memory did not leak. I am running this code in virtual environment of python and am using Windows.
I did not disable tensorboard.