Clean up loggers in root manager's loggerDict to prevent memory buildup#83
Merged
crimsonknave merged 7 commits intomainfrom Oct 17, 2025
Merged
Clean up loggers in root manager's loggerDict to prevent memory buildup#83crimsonknave merged 7 commits intomainfrom
crimsonknave merged 7 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a memory leak issue where decorated functions left persistent logger entries in logging.root.manager.loggerDict, causing memory buildup over time in long-running processes or applications with many function calls.
- Adds logger cleanup in a
finallyblock to ensure loggers are removed even if exceptions occur - Introduces memory leak tests to verify the fix works correctly
- Updates development dependencies to include pytest-memray for memory testing
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| annotated_logger/init.py | Adds logger cleanup logic in finally block and updates version number |
| test/test_memory.py | New test file to verify memory leak prevention and logger cleanup |
| requirements/requirements-dev.txt | Adds pytest-memray and related dependencies for memory testing |
| pyproject.toml | Adds pytest-memray to development dependencies |
| example/calculator.py | Removes commented code line |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
sophiagavrila
approved these changes
Oct 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a memory "leak", where every decorated function left a logger in the
logging.root.manager.loggerDict. Any process that ran for long enough or made lots of calls to annotated methods would start to see memory build up. We now remove the logger for the decorated function in a finally so it's removed regardless of if the function raised an exception.