From f87341d263760577ae9d8bec650d7ce29a79e956 Mon Sep 17 00:00:00 2001 From: Ruda Porto Filgueiras Date: Tue, 14 May 2019 02:15:33 +0200 Subject: [PATCH] Deleting objects to make sure garbage collector will release memory. --- logzio/handler.py | 3 +++ logzio/sender.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/logzio/handler.py b/logzio/handler.py index 0b319f3..a4c741f 100644 --- a/logzio/handler.py +++ b/logzio/handler.py @@ -32,6 +32,9 @@ class LogzioHandler(logging.Handler): backup_logs=backup_logs) logging.Handler.__init__(self) + def __del__(self): + del self.logzio_sender + def extra_fields(self, message): not_allowed_keys = ( diff --git a/logzio/sender.py b/logzio/sender.py index 9c770a5..922d266 100644 --- a/logzio/sender.py +++ b/logzio/sender.py @@ -48,6 +48,11 @@ class LogzioSender: self.queue = queue.Queue() self._initialize_sending_thread() + def __del__(self): + del self.logger + del self.backup_logs + del self.queue + def _initialize_sending_thread(self): self.sending_thread = Thread(target=self._drain_queue) self.sending_thread.daemon = False @@ -153,6 +158,8 @@ class LogzioSender: 'backing up to local file system', number_of_retries) backup_logs(logs_list, self.logger) + del logs_list + def _get_messages_up_to_max_allowed_size(self): logs_list = [] current_size = 0