Use weak reference to break circular reference and memory leaks#3447
Merged
vfdev-5 merged 7 commits intopytorch:masterfrom Sep 19, 2025
Merged
Use weak reference to break circular reference and memory leaks#3447vfdev-5 merged 7 commits intopytorch:masterfrom
vfdev-5 merged 7 commits intopytorch:masterfrom
Conversation
918bbd5 to
c359e0c
Compare
vfdev-5
reviewed
Sep 6, 2025
vfdev-5
reviewed
Sep 6, 2025
68a568a to
f3d6e85
Compare
Collaborator
|
Confirming from my side as well that there is no OOM anymore with this PR: And there is an OOM with python 3.11 |
2c4a36d to
0a427c6
Compare
vfdev-5
reviewed
Sep 7, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a memory leak issue in the Ignite Engine by replacing direct engine references with weak references in event handlers. The circular reference between the engine and its event handlers was preventing proper garbage collection.
- Replaces direct engine references with weak references in event handler storage
- Updates event firing logic to resolve weak references at runtime
- Adds comprehensive test coverage to verify the memory leak fix
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| ignite/engine/engine.py | Updates event handler registration and firing to use weak references instead of direct engine references |
| tests/ignite/engine/test_memory_leaks.py | Adds new test class to verify that engines are properly garbage collected with and without event handlers |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
vfdev-5
reviewed
Sep 12, 2025
vfdev-5
reviewed
Sep 12, 2025
Collaborator
|
@goanpeca can please check why the CI is all red? |
vfdev-5
reviewed
Sep 19, 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.
Fixes #3438
@vfdev-5 I can confirm this PR fixes the issue.