我正在运行一个包括matplotlib的django应用程序,并允许用户指定图形的轴。这可能会导致'Overflow Error: Agg complexity exceeded'。
当发生这种情况时,最多会占用100MB的RAM。通常情况下,我使用fig.gcf()
、plot.close()
和gc.collect()
来释放内存,但是与错误相关联的内存似乎并不与绘图对象相关。
有人知道如何释放该内存吗?
谢谢。
以下是一些代码,它给出了Agg Complexity Error。
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import gc
a = np.arange(1000000)
b = np.random.randn(1000000)
fig = plt.figure(num=1, dpi=100, facecolor='w', edgecolor='w')
fig.set_size_inches(10,7)
ax = fig.add_subplot(111)
ax.plot(a, b)
fig.savefig('yourdesktop/random.png') # code gives me an error here
fig.clf() # normally I use these lines to release the memory
plt.close()
del a, b
gc.collect()