我有一段代码,可以很好地循环一两次,但最终会建立起内存。我尝试用memory_profiler
定位内存泄漏,结果是:
row_nr Memory_usage Memory_diff row_text
470 52.699 MiB 0.000 MiB ax.axis('off')
471 167.504 MiB 114.805 MiB fig.savefig('figname.png', dpi=600)
472 167.504 MiB 0.000 MiB fig.clf()
473 109.711 MiB -57.793 MiB plt.close()
474 109.711 MiB 0.000 MiB gc.collect()`
我创建了这样的数字:fig, ax = plt.subplots()
有什么建议吗109-52= 57 MiB去了?
我正在使用python3.3。
发布于 2020-01-16 02:39:55
# Clear the current axes.
plt.cla()
# Clear the current figure.
plt.clf()
# Closes all the figure windows.
plt.close('all')
plt.close(fig)
gc.collect()
这对我有用。把这些行放在循环的末尾!
https://stackoverflow.com/questions/31156578
复制相似问题