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
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
VisibleDockablesfrom 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.AvaloniaandDock.Model.Mvvm(latest)Dock.Model.Mvvm.Factoryimplementation that overridesCreateLayoutto create a DocumentDock inside a ProportionalDock inside a RootDock and return the root dock.DemoViewModelthat implementsDock.Model.Mvvm.Controls.Documentand a destructor with logging or a breakpointCleanupCommandthat clears theFocusedDockableor the root dock and callsGC.Collect()andGC.WaitForPendingFinalizers()DemoViewModelto 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.10Dock.Avalonia Version:
11.0.0.7