Skip to content

Address memory leaks - #782

Merged
Manodasan Wignarajah (manodasanW) merged 2 commits into
masterfrom
manodasanw/mem_leak_fix
Apr 2, 2021
Merged

Address memory leaks#782
Manodasan Wignarajah (manodasanW) merged 2 commits into
masterfrom
manodasanw/mem_leak_fix

Conversation

@manodasanW

@manodasanW Manodasan Wignarajah (manodasanW) commented Apr 1, 2021

Copy link
Copy Markdown
Member

The changes in this PR addresses the memory leaks observed in the samples from #781. It is a variant of the changes attempted initially in #673 , but addresses some of the concerns about finalizers on the RCW handling release by moving that to the IObjectReference itself which owns the lifetime. In addition, it makes sure in aggregated scenarios, any QIs don't increment the COM ref count maintained by the CLR and that for non aggregated scenarios XAML is informed of those references.

From testing, these changes seem to demonstrate an improvement and no leaks are observed in the samples in #781

Fixes #413

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

First pass looks really good. I will check it out again tomorrow. Two things I would like to see.

  1. A test run against some of the WinUI lifetime tests.
  2. The performance impact of some of these changes. This is now doing a lot more QI work - which the original .NET Native didn't need to do. We may be able to be clever/smart once we confirm it is correct.

Next step is to get the final .NET fix in as well. We should try and validate that leak scenario still exists. I believe the easiest way is to use the WeakReference<T> across the native/managed boundary.

@BenJKuhn

Copy link
Copy Markdown
Contributor

(YAY!)

@manodasanW

Copy link
Copy Markdown
Member Author

The 26 WinUI lifetime tests now all pass.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

I believe the easiest way is to use the WeakReference across the native/managed boundary.

Manodasan Wignarajah (@manodasanW) Any luck trying to use that?

@manodasanW

Copy link
Copy Markdown
Member Author

Aaron R Robinson (@AaronRobinsonMSFT) that is on my list to try out and will get back to you once I do.

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.

WinUI 3 Page objects are being leaked on navigate in a C#/WinRT app

4 participants