Skip to content

Try fix EventRoute weak memory leak - #9463

Merged
dipeshmsft merged 1 commit into
dotnet:release/9.0from
dotnet-campus:t/lindexi/FixEventRouteMemoryLeak
Apr 9, 2025
Merged

dipeshmsft merged 1 commit into
dotnet:release/9.0from
dotnet-campus:t/lindexi/FixEventRouteMemoryLeak

Conversation

@lindexi

@lindexi lindexi commented Jul 25, 2024 •

Copy link
Copy Markdown
Member

Fixes #9467

Reference #6700 and #9460

Description

See #9467

After #6700 , to reduce allocations when tracing routed events, we'll use _traceArguments field to store the trace arguments which cause #9467 issues.

I try clear the reference from _traceArguments after call the TraceRoutedEvent.Trace.

And this pr is a patch, and I think #9460 will be better. Thank you @kasperk81

Customer Impact

See #9467

The memory will still be freed, albeit at a slower pace. Even if this issue is not addressed, it won't have a significant impact. There are two reasons for this. Firstly, the memory will still be freed, it just can't be released immediately. Secondly, this issue only affects those who have enabled Trace, which normal users typically do not do.

Regression

Reference #6700

And Cc @bgrainger

Testing

CI Only.

Risk

Middling

Microsoft Reviewers: Open in CodeFlow

@lindexi
lindexi requested review from a team as code owners July 25, 2024 11:24
@dotnet-policy-service dotnet-policy-service Bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jul 25, 2024
@kasperk81

Copy link
Copy Markdown
Contributor

duplicate of dotnet/runtime#9460

@lindexi

lindexi commented Jul 25, 2024

Copy link
Copy Markdown
Member Author

And I think the #9460 is better than this. This pr is the patch.

@kasperk81

kasperk81 commented Jul 25, 2024 •

Copy link
Copy Markdown
Contributor

i've closed mine.

your fix still has chance of race, when multiple threads are updating the variable. make the variable local? correctness > performance

@lindexi
lindexi force-pushed the t/lindexi/FixEventRouteMemoryLeak branch from 03d93e2 to b6b976a Compare July 26, 2024 01:30
@dipeshmsft

dipeshmsft commented Apr 1, 2025 •

Copy link
Copy Markdown
Member

@lindexi , @h3xds1nz this PR and #9468 are doing the same thing right, the difference being that here we are clearing out the array, whereas in the other PR we have replaced the array with ReadOnlySpan. Is there something more to it that I have missed ?

@lindexi

lindexi commented Apr 1, 2025

Copy link
Copy Markdown
Member Author

@dipeshmsft You are right. My PR #9463 just simple fix. @h3xds1nz 's #9468 can do more improve. I expected this PR to be incorporated into the official release as a way to fix the patch, so I decided to make minimal changes.

@dipeshmsft

Copy link
Copy Markdown
Member

I expected this PR to be incorporated into the official release as a way to fix the patch, so I decided to make minimal changes.

I completely agree with this. I was thinking of taking this for .NET 9 as this is minimal and solves the problem and will be easier to get approved for servicing.

@h3xds1nz

h3xds1nz commented Apr 1, 2025 •

Copy link
Copy Markdown
Member

I completely agree with this. I was thinking of taking this for .NET 9 as this is minimal and solves the problem and will be easier to get approved for servicing.

@dipeshmsft That was basically "our" intention with @lindexi.

@dipeshmsft

Copy link
Copy Markdown
Member

In that case, @lindexi can you retarget this PR to release/9.0 branch.

@lindexi
lindexi changed the base branch from main to release/9.0 April 1, 2025 08:53
@lindexi

lindexi commented Apr 1, 2025

Copy link
Copy Markdown
Member Author

@dipeshmsft Done.

@dipeshmsft
dipeshmsft merged commit 98634f6 into dotnet:release/9.0 Apr 9, 2025
@dipeshmsft

Copy link
Copy Markdown
Member

Thanks a lot @lindexi for taking a stab at this issue.

@github-actions github-actions Bot locked and limited conversation to collaborators May 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Contribution A label for all community Contributions Included in test pass PR metadata: Label to tag PRs, to facilitate with triage Servicing-approved Status:Completed Status:Proposed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WPF control is not reclaimed on NET9 by GC

7 participants