Application hangs on GC.Collect()
See original GitHub issueDescribe the bug Some of our components use DirectX to fast render. On porting I found an issue that application hangs when I put such components in window`s content. After some researching I suggest that the issue relates to GC and interrop services. I prepared a synthetic sample to reproduce this issue. In my sample I create a descendant of SurfaceImageSource. After initialize component I query ISurfaceImageSourceNative interface from SurfaceImageSource.
On Window SizeChanged event I call GC.Collect(). When I run app and start resizing, the application hangs. If I run app under visual studio debugger, the application hangs with Visual Studio together.
If I comment GC.Collect (ln 43) or comment Marshal.GetObjectForIUnknown(pOut) line (ln 38), all works fine. There is why I suggested that issue relates to garbage collector and interrop services.
Steps to reproduce the bug
- Compile and run attached project
- Resize a window. Application will hang.
- Comment line 43 (GC.Collect()) and run application again. All will work without errors.
- Uncomment line 43 and comment lines 38-40. All will work good again.
Version Info
Windows 10 1903 (OS Build 18362.1082)
NuGet package version:
WinUI 3.0.0-preview2.200713.0
Windows app type:
UWP | Win32 |
---|---|
No | Yes |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
After looking into the @BorzillaR sample, I see that the issue reproduces when the
coreclr!RCWWalker::s_pGCManager
field is not null. So I can hardly imagine how to work with native (COM) Windows runtime types since this may lead to application hanging.To reproduce this, you can create a blank app from the Visual Studio template and replace the MainWindow ctor with the following code:
If you attach a debugger to the application, you’ll see a deadlock with the following call stack:
Great, thanks @angelazhangmsft!
I’m going to close out this issue now that preview3 has been released. @BorzillaR, if you see this issue again, please respond and I will re-open. Thanks!