Memory usage growing after each DBus method call



Hi all,

I noticed my application's memory usage is constantly growing after each DBus call, reaching huge amounts of memory, such as more than 2GB.

I tried looking at the test_gdbus test cases, and it turns out a simple call to test_python_calls_sync() will increase the memory usage, without any possibility to reclaim that memory.

Here's a simple test case add-on to test_gdbus.py regarding this:

diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py
index 805633a..c81ff7d 100644
--- a/tests/test_gdbus.py
+++ b/tests/test_gdbus.py
@@ -208,3 +208,27 @@ class TestGDBusClient(unittest.TestCase):

         self.assertTrue(isinstance(data['error'], Exception))
         self.assertTrue('InvalidArgs' in str(data['error']), str(data['error']))
+
+    def old_dbus(self):
+        import dbus
+        dbus.Interface(dbus.SessionBus().get_object('org.freedesktop.DBus',
+                       '/org/freedesktop/DBus'), 'org.freedesktop.DBus',).ListNames()
+
+    def test_python_calls_leak(self):
+        import psutil
+        proc = psutil.Process(psutil.os.getpid())
+        iteration, stable_count = 0, 0
+        usage = proc.get_memory_info()[0]
+        while True:
+#            self.old_dbus()
+            self.test_python_calls_sync()
+            new_usage = proc.get_memory_info()[0]
+            if new_usage == usage:
+                stable_count += 1
+            else:
+                stable_count = 0
+                usage = new_usage
+            if stable_count > 10 or iteration == 100:
+                break
+            iteration += 1
+        self.assertLess(iteration, 100)


It calls test_python_calls_sync() successively and inspects the memory usage, waiting for it to stabilize. It will consider it has stabilized after getting no memory change through 10 iterations.

This test case fails, but succeeds if using the old dbus bindings.

I'm not sure how to interpret this, I tried calling gc.collect after each iteration, but it doesn't seem to collect anything. Also, I tried to unref/del the GLib.Variant object returned by the call, without any success. Valgrind didn't help much either, as I'm not very acquainted with it.

I'd be glad to get any insight on this matter, as for the moment it prevents me from using python-gi for my dbus needs, though i would very much like to do so, especially to benefit from its thread-safe nature.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]