Open ArchLeaders opened 1 month ago
Unfortunately it's Avalonia fault. Some of the leaks are fixed in the latest master, but some are still waiting for a fix
https://github.com/AvaloniaUI/Avalonia/issues/15465
https://github.com/AvaloniaUI/Avalonia/issues/15444
https://github.com/AvaloniaUI/Avalonia/issues/15443
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:
Dock.Avalonia
andDock.Model.Mvvm
(latest)Dock.Model.Mvvm.Factory
implementation that overridesCreateLayout
to create a DocumentDock inside a ProportionalDock inside a RootDock and return the root dock.DemoViewModel
that implementsDock.Model.Mvvm.Controls.Document
and a destructor with logging or a breakpointCleanupCommand
that clears theFocusedDockable
or the root dock and callsGC.Collect()
andGC.WaitForPendingFinalizers()
DemoViewModel
to the DocumentDock, close one and call the cleanup command. Observe that the destructor is never called.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