Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
tacaswell committed Mar 15, 2023
commit 01390c53fcc777207a5f2c9b93f1cf8d3799e9c7
2 changes: 2 additions & 0 deletions lib/matplotlib/_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,6 @@ def warn_external(message, category=None):
frame.f_globals.get("__name__", "")):
break
frame = frame.f_back
# premetively break reference cycle between locals and the frame
del frame
warnings.warn(message, category, stacklevel)
2 changes: 2 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def _get_running_interactive_framework():
if frame.f_code in codes:
return "tk"
frame = frame.f_back
# premetively break reference cycle between locals and the frame
del frame
macosx = sys.modules.get("matplotlib.backends._macosx")
if macosx and macosx.event_loop_is_running():
return "macosx"
Expand Down