From 49b7106d7151c61c6a44977ee31558e1151abb66 Mon Sep 17 00:00:00 2001 From: rikka Date: Tue, 3 Dec 2024 22:39:56 +0800 Subject: [PATCH 1/2] fix: Memory leak caused by scanp command due to handler's reference to plugin instance. close #2412 --- plugins/plugin_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/plugin_manager.py b/plugins/plugin_manager.py index cecf75d65..8eb74875f 100644 --- a/plugins/plugin_manager.py +++ b/plugins/plugin_manager.py @@ -151,6 +151,8 @@ def activate_plugins(self): # 生成新开启的插件实例 self.disable_plugin(name) failed_plugins.append(name) continue + if name in self.instances: + self.instances[name].handlers.clear() self.instances[name] = instance for event in instance.handlers: if event not in self.listening_plugins: From 2a351ca41535338ae948cd945864d6bb6df925c3 Mon Sep 17 00:00:00 2001 From: rikka Date: Thu, 5 Dec 2024 00:33:00 +0800 Subject: [PATCH 2/2] fix(reloadp): clear handlers when reloading plugin to avoid memory leaks --- plugins/plugin_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/plugin_manager.py b/plugins/plugin_manager.py index 8eb74875f..1cfd76cfa 100644 --- a/plugins/plugin_manager.py +++ b/plugins/plugin_manager.py @@ -167,6 +167,8 @@ def reload_plugin(self, name: str): for event in self.listening_plugins: if name in self.listening_plugins[event]: self.listening_plugins[event].remove(name) + if name in self.instances: + self.instances[name].handlers.clear() del self.instances[name] self.activate_plugins() return True