安装 pip install -U memory_profiler 案例 from memory_profiler import profile @profile(precision=4) def my_func(): a = [1] * (10 ** 6) b = [2] * (2 * 10 ** 7) del b return a 效果 通过逐行内存诊断,找到了内存泄漏的罪魁祸首