From ffde7e8ad99be34c9de5f7a173589a90d6e9da45 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Sun, 27 Jul 2025 23:31:55 +0300 Subject: [PATCH] fix(Adaptor): Add cleanup function to handle possible memory leak --- scrapling/parser.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scrapling/parser.py b/scrapling/parser.py index 9387711..3aed83b 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -181,6 +181,14 @@ class Adaptor(SelectorsGeneration): else {} ) + def __del__(self): + """Ensure cleanup happens""" + if hasattr(self, "_storage") and self._storage: + try: + self._storage.close() + finally: + self._storage = None + # Node functionalities, I wanted to move to a separate Mixin class, but it had a slight impact on performance @staticmethod def _is_text_node(