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.
Unfortunately, activation email could not send to your email. Please try again.

DockingManager MVVM ViewModel not disposed after closing tab.

Thread ID:

Created:

Updated:

Platform:

Replies:

123518 Mar 24,2016 11:12 AM Mar 29,2016 05:06 AM WPF 3
loading
Tags: DockingManager
Scot Braze
Asked On March 24, 2016 11:12 AM

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

Vijayalakshmi Roopkumar [Syncfusion]
Replied On March 28, 2016 09:23 AM

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.

Scot Braze
Replied On March 28, 2016 10:05 AM

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.

Vijayalakshmi Roopkumar [Syncfusion]
Replied On March 29, 2016 05:06 AM

Hi Scot,

Thank you for your update,

We will wait to hear from you.

Regards,
Vijayalakshmi V.R.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;