我正在展示
lines.pop(0)
l.remove()和结合
del l使用的技巧。
from matplotlib import pyplotimport numpy, weakrefa = numpy.arange(int(1e3))fig = pyplot.Figure()ax = fig.add_subplot(1, 1, 1)lines = ax.plot(a)l = lines.pop(0)wl = weakref.ref(l) # create a weak reference to see if references still exist#to this objectprint wl # not deadl.remove()print wl # not deaddel lprint wl # dead (remove either of the steps above and this is still live)
我检查了您的大型数据集,并在系统监视器上也确认了内存的释放。
当然,更简单的方法(当不进行故障排除时)是从列表中弹出它并
remove在不创建硬引用的情况下调用该行对象:
lines.pop(0).remove()



