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

Memory leak to AdonisWindow from HandleTitleBarActualHeightChanged #207

Open
hypehuman opened this issue Feb 13, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@hypehuman
Copy link

Describe the bug
AdonisWindow is not being removed from memory after the window is closed. The window, its content, and its DataContext (i.e., business logic) is therefore not getting garbage collected.

To Reproduce
Steps to reproduce the behavior:

  1. Build and run the following WPF application: AdonisLeakTest.zip
  2. Click on 'Launch Simulation' (this opens a new AdonisWindow).
  3. Close the new window, but keep main window open.
  4. Force or wait for garbage collection.
  5. BUG: The closed AdonisWindow, its Content (of type SimulationView) and the its Content.DataContext (of type SimulationVM) still exist in memory.

Expected behavior
After closing the window, the AdonisWindow, the SimulationView, and the SimulationVM should have been eligible for garbage collection. However, there is a memory leak keeping them alive. From the DotMemory screenshots below, it looks like the culprit is a DependencyObjectPropertyDescriptor for the ActualHeight property. This descriptor was added in AdonisWindow.HandleTitleBarActualHeightChanged.

The method uses DependencyPropertyDescriptor.AddValueChanged. I think it needs to either use a weak event, or remove the handler at some point.

Screenshots
These screenshots are from JetBrains DotMemory, from a snapshot taken after doing "To Reproduce" and then forcing garbage collection.

Here you can see that SimulationVM is still in memory, and that AdonisWindow is keeping it alive. The path contains an EventHandler and a DependencyObjectPropertyDescriptor.

leak path

Here is the stack trace for the creation of the EventHandler in the previous screenshot. It shows that the event handler was created from AdonisWindow.HandleTitleBarActualHeightChanged while the window was opening.

leak stack trace

Finally, here are some properties of the aforementioned DependencyObjectPropertyDescriptor, confirming that it's related to "ActualHeight".

leak properties

@hypehuman hypehuman added the bug Something isn't working label Feb 13, 2024
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

1 participant