From 1e91131cbfcfed1ad654e6750b934bdcbdd394d2 2023-11-23 12:45:20
From: Hanno Perrey <hanno.perrey@dvel.se>
Date: 2023-11-23 12:45:20
Subject: [PATCH] Fix memory leak in Qt event loop integration (#14240)

See: https://github.com/ipython/ipython/issues/14240

- the QEventLoop, `event_loop`, is not deleted when exiting the scope as
passing `app` to the constructor parents the object to `app`. This
creates a memory leak as QEventLoop objects are being accumulated.
- issue reported by and fix suggested by @pag

---

diff --git a/IPython/terminal/pt_inputhooks/qt.py b/IPython/terminal/pt_inputhooks/qt.py
index cf6d11e..638ea2b 100644
--- a/IPython/terminal/pt_inputhooks/qt.py
+++ b/IPython/terminal/pt_inputhooks/qt.py
@@ -84,3 +84,5 @@ def inputhook(context):
                 _exec(event_loop)
         finally:
             notifier.setEnabled(False)
+    # make sure that the QObject is being deleted
+    event_loop.setParent(None)