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

[Bug] [Memory Leak] Closed Documents are not collected by the GC #340

Open
ArchLeaders opened this issue May 21, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@ArchLeaders
Copy link

ArchLeaders commented May 21, 2024

When closing documents in a DocumentDock, the GC never collects the removed view models.

I'm not very good with memory diagnostics, but from what I could understand, several Avalonia.PropertyStore.EffectiveValue<Object> instances hold the view model.

From what I can tell these property stores are part of the visual tree, which is not something I am familiar with.

I also observed that clearing the VisibleDockables from both the DocumentDock and ProportionalDock (parent of the DocumentDock) allows every open or closed document to be collected by the GC. Clearing either one alone does not work.

To recreate the issue:

  • Create a new Avalonia project and add Dock.Avalonia and Dock.Model.Mvvm (latest)
  • Create a main window with a DockControl bound to an IRootDock (Layout)
  • Create a Dock.Model.Mvvm.Factory implementation that overrides CreateLayout to create a DocumentDock inside a ProportionalDock inside a RootDock and return the root dock.
  • Create a DemoViewModel that implements Dock.Model.Mvvm.Controls.Document and a destructor with logging or a breakpoint
  • Create a CleanupCommand that clears the FocusedDockable or the root dock and calls GC.Collect() and GC.WaitForPendingFinalizers()
  • Add two new instances of DemoViewModel to the DocumentDock, close one and call the cleanup command. Observe that the destructor is never called.
  • Close the second instance and observe that both DemoViewModel's are destructed (the entire dock area is also missing after closing the last document).

You can find a minimal sample app replicating this on my GitHub: ArchLeaders/DockAvalonia-MemoryLeakIssue


Avalonia Version: 11.0.10
Dock.Avalonia Version: 11.0.0.7

@BAndysc
Copy link
Contributor

BAndysc commented May 21, 2024

Unfortunately it's Avalonia fault. Some of the leaks are fixed in the latest master, but some are still waiting for a fix

AvaloniaUI/Avalonia#15465

AvaloniaUI/Avalonia#15444

AvaloniaUI/Avalonia#15443

AvaloniaUI/Avalonia#15094

AvaloniaUI/Avalonia#15455

@wieslawsoltes wieslawsoltes added the bug Something isn't working label Jun 1, 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

3 participants