Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak on cloning functions with update defs #7735

Merged
merged 2 commits into from
Aug 2, 2023

Conversation

abadams
Copy link
Member

@abadams abadams commented Aug 1, 2023

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.

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.
Copy link
Contributor

@steven-johnson steven-johnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please leave a comment here so it doesn't get changed back

@steven-johnson
Copy link
Contributor

Failures unrelated, landing

@steven-johnson steven-johnson merged commit 8fe4f99 into main Aug 2, 2023
3 checks passed
@steven-johnson steven-johnson deleted the abadams/fix_leak_on_clone_update branch August 2, 2023 16:39
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants