Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commit353275c
committed
Break reference cycle Line2D <-> Line2D._lineFunc.
Upon drawing, Line2D objects would store a reference to one of their ownbound methods as their `_lineFunc` argument. This would lead to thembeing gc'ed not when going out of scope, but only when the "true" gckicks 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 gcimport weakreffrom matplotlib import pyplot as pltdef 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 theLine2D only upon explicit garbage collection. After the patch, both arecollected immediately.1 parent2a7f606 commit353275c
2 files changed
+3
-12
lines changedLines changed: 2 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
445 | 445 |
| |
446 | 446 |
| |
447 | 447 |
| |
448 |
| - | |
449 |
| - | |
450 |
| - | |
451 |
| - | |
452 |
| - | |
453 |
| - | |
454 | 448 |
| |
455 | 449 |
| |
456 | 450 |
| |
| |||
784 | 778 |
| |
785 | 779 |
| |
786 | 780 |
| |
787 |
| - | |
| 781 | + | |
788 | 782 |
| |
789 | 783 |
| |
790 | 784 |
| |
| |||
807 | 801 |
| |
808 | 802 |
| |
809 | 803 |
| |
810 |
| - | |
| 804 | + | |
811 | 805 |
| |
812 | 806 |
| |
813 | 807 |
| |
| |||
1250 | 1244 |
| |
1251 | 1245 |
| |
1252 | 1246 |
| |
1253 |
| - | |
1254 |
| - | |
1255 |
| - | |
1256 | 1247 |
| |
1257 | 1248 |
| |
1258 | 1249 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
236 | 236 |
| |
237 | 237 |
| |
238 | 238 |
| |
239 |
| - | |
| 239 | + | |
240 | 240 |
| |
241 | 241 |
| |
242 | 242 |
| |
|
0 commit comments
Comments
(0)