Skip to content

Commit

Permalink
Fix clearing output references with %reset out (#14133)
Browse files Browse the repository at this point in the history
This should fix #14129. Namely the second reference to the output is
stored in `user_ns_hidden`. That was already cleared during hard
`%reset` but was not cleared when using `%reset out`. Manual
`gc.collect()` is still required.
  • Loading branch information
Carreau committed Aug 28, 2023
2 parents b4cb7e4 + 3c113ad commit 7f4fe75
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion IPython/core/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,14 @@ def flush(self):

for n in range(1,self.prompt_count + 1):
key = '_'+repr(n)
try:
del self.shell.user_ns_hidden[key]
except KeyError:
pass
try:
del self.shell.user_ns[key]
except: pass
except KeyError:
pass
# In some embedded circumstances, the user_ns doesn't have the
# '_oh' key set up.
oh = self.shell.user_ns.get('_oh', None)
Expand Down

0 comments on commit 7f4fe75

Please sign in to comment.