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

AdonisWindow not getting garbage collected #197

Open
RossMetacraft opened this issue Oct 3, 2022 · 2 comments
Open

AdonisWindow not getting garbage collected #197

RossMetacraft opened this issue Oct 3, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@RossMetacraft
Copy link

Hello, and thank you for the fantastic UI framework!

When I open a window which is a subclass of AdonisWindow, then close it, then force a garbage collection pass, the finalizer for the window is not called, even though my code has no references to the window. If I change the window so that it derives directly from System.Windows.Window, then the finalizer is called as expected when I force a GC after closing the window.

I am fairly new to WPF so I may be doing something wrong and missing something obvious, but I am able to reproduce this in a very simple application.

To reproduce:

  1. Create an application with two window classes, MainWindow and SecondaryWindow.
  2. Add the usual Adonis resources to App.xaml, Dark or Light theme, doesn't matter which.
  3. Modify SecondaryWindow such that it derives from AdonisWindow.
  4. Add a finalizer to SecondaryWindow and in the finalizer, add a Debug.WriteLine statement in order to know when the finalizer is called.
  5. On MainWindow, add a button labeled "Open Window" and in its codebehind handler, instantiate SecondaryWindow and display it with Show().
  6. On MainWindow, add another button labeled "Collect" and in its codebehind handler, call GC.Collect() and GC.WaitForPendingFinalizers() and then GC.Collect() again, to ensure all unreferenced objects are collected.
  7. Run the application, press the "Open Window" button.
  8. After the SecondaryWindow opens, close it with the X.
  9. Press the "Collect" button, and observe that the SecondaryWindow finalizer is not called.

If you change SecondaryWindow to derive directly from System.Windows.Window, then the finalizer is called.

The expectation is that the SecondaryWindow will be fully unreferenced after it is closed, and its finalizer will be called when a full garbage collection occurs.

@RossMetacraft RossMetacraft added the bug Something isn't working label Oct 3, 2022
@RossMetacraft
Copy link
Author

I've attached an app that reproduces the problem. It has two buttons, one to create an Adonis window, and the other to create a regular window that does not derive from AdonisWindow. You can see that the Adonis windows are not garbage collected, while the regular windows are.
AdonisMemoryLeakTest.zip

@nrankin18
Copy link

Any update on this? I also observed this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants