Fix leak on cloning functions with update defs#7735
Merged
steven-johnson merged 2 commits intomainfrom Aug 2, 2023
Merged
Conversation
When cloning a Func with an update def, the remapping map resulting from the deep copy may already contain a key for the wrapped function pointing to a strong reference to itself. The reasons are unclear to me, but it means that emplace silently does nothing and we get a memory leak because the cloned Func's update definition has a strong self-reference after the remapping is applied. We want to replace it with a weak reference, so this PR changes things to use operator[] instead of emplace.
steven-johnson
approved these changes
Aug 1, 2023
Contributor
steven-johnson
left a comment
There was a problem hiding this comment.
LGTM but please leave a comment here so it doesn't get changed back
Contributor
|
Failures unrelated, landing |
ardier
pushed a commit
to ardier/Halide-mutation
that referenced
this pull request
Mar 3, 2024
* Fix leak on cloning functions with update defs When cloning a Func with an update def, the remapping map resulting from the deep copy may already contain a key for the wrapped function pointing to a strong reference to itself. The reasons are unclear to me, but it means that emplace silently does nothing and we get a memory leak because the cloned Func's update definition has a strong self-reference after the remapping is applied. We want to replace it with a weak reference, so this PR changes things to use operator[] instead of emplace. * Add comment
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.
When cloning a Func with an update def, the remapping map resulting from the deep copy may already contain a key for the wrapped function pointing to a strong reference to itself. The reasons are unclear to me, but it means that emplace silently does nothing and we get a memory leak because the cloned Func's update definition has a strong self-reference after the remapping is applied.
We want to replace it with a weak reference, so this PR changes things to use operator[] instead of emplace.