diff --git a/xbob/db/replay/query.py b/xbob/db/replay/query.py
index 61849eb2be6e9672fdeb6e8d905934e3b7788c5f..57be3d83d3e0885b8a94cd98b3b9f2da47809b60 100644
--- a/xbob/db/replay/query.py
+++ b/xbob/db/replay/query.py
@@ -28,6 +28,10 @@ class Database(object):
     # opens a session to the database - keep it open until the end
     self.connect()
 
+  def __del__(self):
+    """Releases the opened file descriptor"""
+    if self.session: self.session.bind.dispose()
+
   def connect(self):
     """Tries connecting or re-connecting to the database"""
     if not os.path.exists(SQLITE_FILE):