Skip to content

Conversation

@tarekgh
Copy link
Member

@tarekgh tarekgh commented Aug 19, 2022

Fixes #73832

@ghost
Copy link

ghost commented Aug 19, 2022

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #73832

Author: tarekgh
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@tarekgh tarekgh changed the title Fix leaks caused by not disposing the parent scoped ServiceProvider Fix leak caused by not disposing the parent scoped ServiceProvider Aug 19, 2022
@tarekgh tarekgh added this to the 7.0.0 milestone Aug 19, 2022
@tarekgh tarekgh requested review from davidfowl and eerhardt August 19, 2022 17:08
@tarekgh
Copy link
Member Author

tarekgh commented Aug 19, 2022

CC @ericstj

@tarekgh tarekgh changed the title Fix leak caused by not disposing the parent scoped ServiceProvider Fix leak caused by not disposing the scoped parent service provider Aug 19, 2022
// If this ServiceProviderEngineScope instance is a root scope, disposing this instance will need to dispose the RootProvider too.
// Otherwise the RootProvider will never get disposed and will leak.
// Note, if the RootProvider get disposed first, it will automatically dispose all attached ServiceProviderEngineScope objects.
RootProvider.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

Why cant this just noop internally?

Copy link
Member Author

@tarekgh tarekgh Aug 20, 2022

Choose a reason for hiding this comment

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

It is simpler. no?

More code, more bugs :-) imagine in the future we add anything to the ServicePrivder dispose method.

Copy link
Member

Choose a reason for hiding this comment

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

Why cant this just noop internally?

By "just noop internally", you mean adding the if check in ServiceProvider Dispose?

Copy link
Member

Choose a reason for hiding this comment

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

Yep.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM

@tarekgh tarekgh merged commit cb52e3b into dotnet:main Aug 22, 2022
@tarekgh
Copy link
Member Author

tarekgh commented Aug 22, 2022

/backport to release/7.0-rc1

@github-actions
Copy link
Contributor

Started backporting to release/7.0-rc1: https://github.com/dotnet/runtime/actions/runs/2905770618

@tarekgh
Copy link
Member Author

tarekgh commented Aug 22, 2022

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2905993688

@ghost ghost locked as resolved and limited conversation to collaborators Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DependencyInjectionEventSource Memory leak

3 participants