Duncan MacIntyre
Duncan MacIntyre

Reputation: 115

Garbage collection for matplotlib figures

Various sources (e.g. this post) make it sound like garbage collection occurs properly for figures created with matplotlib.figure.Figure() but not for figures created with matplotlib.pyplot.figure(). Unfortunately, I haven't been able to find documentation of this.

Is it true that Python will garbage collect old figures created with matplotlib.figure.Figure() that are no longer used? For example...

Thank you!

(I apologize if this isn't actually "garbage collection." If so, let me know. 🙂)

Edit: fixed typo

Upvotes: 0

Views: 405

Answers (1)

0x263A
0x263A

Reputation: 1859

The matplotlib.pyplot.figure documentation states you should explicitly call pyplot.close on the figures you are not using. Otherwise pyplot will not properly clean up memory. Check out the notes at the bottom here.

Upvotes: 2

Related Questions