You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upon drawing, Line2D objects would store a reference to one of their own
bound methods as their `_lineFunc` argument. This would lead to them
being gc'ed not when going out of scope, but only when the "true" gc
kicks in; additionally this led to some pickle-related bugs (#3627).
One can easily sidestep this problem by not storing this bound method.
To check the behavior, try (py3.4+ only):
```
import gc
import weakref
from matplotlib import pyplot as plt
def f():
fig, ax = plt.subplots()
img = ax.imshow([[0, 1], [2, 3]])
weakref.finalize(img, print, "gc'ing image")
l, = plt.plot([0, 1])
weakref.finalize(l, print, "gc'ing line")
fig.canvas.draw()
img.remove()
l.remove()
f()
print("we have left the function")
gc.collect()
print("and cleaned up our mess")
```
Before the patch, the AxesImage is gc'ed when the function exits but the
Line2D only upon explicit garbage collection. After the patch, both are
collected immediately.
0 commit comments