Skip to content

Commit 01390c5

Browse files
committed
MNT: delete references to frame objects
This is to help prevent reference cycles between the frames and the locals in that frame. While garbage collection should in most cases take care of this eventually, we can help the interpreter out and break the cycle before we return.
1 parent db0c7c3 commit 01390c5

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

lib/matplotlib/_api/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,6 @@ def warn_external(message, category=None):
385385
frame.f_globals.get("__name__", "")):
386386
break
387387
frame = frame.f_back
388+
# premetively break reference cycle between locals and the frame
389+
del frame
388390
warnings.warn(message, category, stacklevel)

lib/matplotlib/cbook.py

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def _get_running_interactive_framework():
6767
if frame.f_code in codes:
6868
return "tk"
6969
frame = frame.f_back
70+
# premetively break reference cycle between locals and the frame
71+
del frame
7072
macosx = sys.modules.get("matplotlib.backends._macosx")
7173
if macosx and macosx.event_loop_is_running():
7274
return "macosx"

0 commit comments

Comments
 (0)