From 7f4fe75c49d9bf5773c1958eab75dd1d0be10f72 2023-08-28 08:31:58 From: Matthias Bussonnier Date: 2023-08-28 08:31:58 Subject: [PATCH] Fix clearing output references with `%reset out` (#14133) 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. --- diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index aba4f90..b411f11 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -297,8 +297,13 @@ class DisplayHook(Configurable): 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)