We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

DockingManager MVVM ViewModel not disposed after closing tab.

Thanks again for your help on my last issue.  I have a new issue where I can't seem to get my ViewModels to dispose properly when they are removed from the docking manager children collection.  I did see the article on the AutomationPeer fix and have added a FakeUserControlPeer that subclasses UserControlAutomationPeer but the override does not seem to be called.  I tried this at the window level with the same results.

setting the e.TargetTabItem.DataContext = null in the TabClosed event cleans up most of the anchors to the VM, but there is still a static drag drop handler that is attached.  I am sure there is something I am missing or doing wrong.

I am removing the FrameworkElement from the dockingManager.Children list on line 150.  I am also setting the FrameworkElement.DataContext = null (line 65) just to ensure that any command predicates are unhooked before attempting to dispose.  finally, i did add a force GC collection menu item to force the GC to run.  This is for testing only.

To prove that the VM will properly dispose there are 2 options to spawn a window.

1.  Add Content Item - this adds a tabbed item to the docking manager.  This window is not disposed until the shell closes.
2. Open New Content Window - this just opens a new window.  When this window is closed, the VM properly disposes (click Garbage Collect if you don't want to wait).

When a ViewModel is disposed, you will see text to the output window in the form of:

DEBUG: ContentPageViewModel (7880838) Finalized. Priority: None. Timestamp:2016-03-24 10:51:55Z.

Please make sure that you are in debug mode or you won't see the trace output.  

Thanks in advance,

scot.

P.S. the IDisposable implementation is very rudimentary and will be implemented differently in a production application.  This is was put together quickly for demo purposes.

Attachment: SyncfusionDockingDispose_61698d.zip

3 Replies

VR Vijayalakshmi Roopkumar Syncfusion Team March 28, 2016 01:23 PM UTC

Hi Scot,

We have checked the reported memory leak problem with the DockingManager and we have found that the survived instance of Memory object in ViewModel is 5. Could you please let us know have you got the same instance of memory leak? We will further analyse on this reported problem and update you. In mean time, if you would like to provide any information about your problem, please share with us.

Regards,
Vijayalakshmi V.R.


SB Scot Braze March 28, 2016 02:05 PM UTC

I think i may have it working in my demo application.  I will respond to this thread with an updated zip file when i have confirmed things.  This will allow others to benefit from this thread.  Just FYI, i changed the following in the MainWindowViewModel class.

            AddContentCommand = new DelegateCommand(() =>
            {
                var vm = container.Resolve<ContentPageViewModel>();
                Action handler = null;
                handler = delegate
                {
                    vm.RequestClose -= handler;
                    DockWindows.Remove(vm);
                };
                vm.RequestClose += handler;
                DockWindows.Add(vm);
            });

i will post complete working code once i am sure that i have this fixed.

thanks again for the excellent support.


VR Vijayalakshmi Roopkumar Syncfusion Team March 29, 2016 09:06 AM UTC

Hi Scot,

Thank you for your update,

We will wait to hear from you.

Regards,
Vijayalakshmi V.R.

Loader.
Live Chat Icon For mobile
Up arrow icon