Memory Leak with Async DataPortal calls?

Memory Leak with Async DataPortal calls?

Old forum URL: forums.lhotka.net/forums/t/9920.aspx


ksirmons posted on Wednesday, January 05, 2011

Howdy,

I am having an issue similar to this poster's problem (http://forums.lhotka.net/forums/p/9209/43741.aspx).

I have used Windbg attached to Silverlight and it appears that my ViewModels are not being GC'ed.  

It appears that the Async DataPortal callback EventHandler is holding a reference to the VM.  

Any help would be appreciated.

Thank you,

Keith

(CSLA 4.0.1)

 

Below is the output of Windbg:

 

0:008> !dumpheap -type Eis.Silverlight.SecurityAdminModule.ViewModels.UserAdministrationViewModel

 Address       MT     Size

0c44bb48 07624ab4      104     

 

0:008> !gcroot 0c44bb48 

Note: Roots found on stacks may be false positives. Run "!help gcroot" for

more info.

Scan Thread 5 OSTHread 1e04

Scan Thread 43 OSTHread 1888

Scan Thread 44 OSTHread 365c

Scan Thread 45 OSTHread 2d90

DOMAIN(10958B10):HANDLE(Strong):29f1198:Root:  0c45c3d0(System.Threading._TimerCallback)->

  0c45c278(System.ServiceModel.Channels.HttpChannelFactory+HttpRequestChannel+HttpChannelAsyncRequest)->

  0c45c168(System.ServiceModel.Channels.ServiceChannel+SendAsyncResult)->

  0c45a440(System.ServiceModel.ClientBase`1+AsyncOperationContext[[Csla.WcfPortal.IWcfPortal, Csla]])->

  0c45a40c(System.Threading.SendOrPostCallback)->

  0c458dfc(Csla.WcfPortal.WcfPortalClient)->

  0c45a3ac(System.EventHandler`1[[Csla.WcfPortal.FetchCompletedEventArgs, Csla]])->

  0c457a24(Csla.DataPortalClient.WcfProxy`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]])->

  0c457ad0(System.EventHandler`1[[Csla.DataPortalResult`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]], Csla]])->

  0c4579ec(Csla.DataPortal`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]])->

  0c4577b4(System.EventHandler`1[[Csla.DataPortalResult`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]], Csla]])->

  0c44bb48(Eis.Silverlight.SecurityAdminModule.ViewModels.UserAdministrationViewModel)

DOMAIN(10958B10):HANDLE(Pinned):29f12f8:Root:  0cfe4250(System.Object[])->

  0c208858(Eis.Silverlight.App)->

  0c214ab0(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c214afc(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c214938(System.Windows.ResourceDictionary)->

  0c214990(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c2149dc(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c2148d4(MS.Internal.ResourceDictionaryCollection)->

  0c214a18(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c214a64(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c20fafc(System.Windows.ResourceDictionary)->

  0c20fea4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c2147e4(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c214870(System.Windows.DataTemplate)->

  0c4614d0(Microsoft.Practices.Prism.Interactivity.InteractionRequest.PopupChildWindowAction)->

  0c460cfc(System.Windows.Controls.Border)->

  0c44cd84(Eis.Silverlight.Library.Controls.MainContentContainerControl)->

  0c44deac(System.Windows.Controls.StackPanel)->

  0c44df10(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c4a32f4(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c454d6c(System.Windows.Controls.Border)->

  0c454dd0(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c454e1c(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c454744(System.Windows.Controls.StackPanel)->

  0c4547a8(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0c4547f4(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0c4549ac(System.Windows.Controls.ItemsControl)->

  0c454bf8(System.Windows.DataContextChangedEventHandler)->

  0c454ba4(System.Windows.Data.BindingExpression)->

  0c44bb48(Eis.Silverlight.SecurityAdminModule.ViewModels.UserAdministrationViewModel)

Here is the code in the VM:
   private void LoadExistingUser(int userId)
        {
           IsBusy = true;

            UserManagementUnitOfWork.Get(
                userId, 
                (o, e) =>
                       {
                           if (e.Error == null)
                           {
                               DomainList = ((UserManagementUnitOfWork)e.Object).DomainNames;
                               allGroupInfoCollection = ((UserManagementUnitOfWork)e.Object).SecurityGroups;

                               Model = ((UserManagementUnitOfWork)e.Object).User;
                               BuildSecurityGroupLists();
                               IsBusy = false;
                           }
                       });
}

And the Get method in the UOW object:
    public static void Get(int id, EventHandler<DataPortalResult<UserManagementUnitOfWork>> callback)
        {
            var dp = new DataPortal<UserManagementUnitOfWork>();
            dp.FetchCompleted += callback;
            dp.BeginFetch(id);
        }

 

sergeyb replied on Wednesday, January 05, 2011

Your second trace is almost certianly caused by datatemplate related memory leak in SL 4.  Your first trace has TimerCallBack.  Do you use any timers in your app?  I know that Busy animation is using timer, so if you take snapshot while it is running, you will likely have it on the callstack.

ksirmons replied on Thursday, January 06, 2011

If the memory leak is coming from the datatemplate, let me post the windbg for the view below.

It shows that a DataTemplate is referencing the view.

I am not using any timers directly, but I do use the Busy Animation control from the SL4 toolkit (4.0.40412.2000).

I have seen some workarounds for the DataTemplate issue on the SL forums and will see if the workaround will fix the issue.

Thank you,

Keith

 

0:032> !gcroot 0bf29eb4 

Note: Roots found on stacks may be false positives. Run "!help gcroot" for

more info.

Scan Thread 4 OSTHread 7cc

Scan Thread 43 OSTHread 1510

Scan Thread 44 OSTHread 1888

Scan Thread 45 OSTHread 32f4

DOMAIN(074A08E0):HANDLE(Strong):5921190:Root:  0bf3b840(System.Threading._TimerCallback)->

  0bf3b6dc(System.ServiceModel.Channels.HttpChannelFactory+HttpRequestChannel+HttpChannelAsyncRequest)->

  0bf3b5ac(System.ServiceModel.Channels.ServiceChannel+SendAsyncResult)->

  0bf39884(System.ServiceModel.ClientBase`1+AsyncOperationContext[[Csla.WcfPortal.IWcfPortal, Csla]])->

  0bf39850(System.Threading.SendOrPostCallback)->

  0bf38240(Csla.WcfPortal.WcfPortalClient)->

  0bf397f0(System.EventHandler`1[[Csla.WcfPortal.FetchCompletedEventArgs, Csla]])->

  0bf36e30(Csla.DataPortalClient.WcfProxy`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]])->

  0bf36ef8(System.EventHandler`1[[Csla.DataPortalResult`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]], Csla]])->

  0bf36df8(Csla.DataPortal`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]])->

  0bf36bc0(System.EventHandler`1[[Csla.DataPortalResult`1[[Eis.Library.SecurityManagement.UserManagementUnitOfWork, Eis.Library]], Csla]])->

  0bf29ba0(Eis.Silverlight.SecurityAdminModule.ViewModels.UserAdministrationViewModel)->

  0bf29e20(Microsoft.Practices.Prism.Interactivity.InteractionRequest.InteractionRequest`1[[Microsoft.Practices.Prism.Interactivity.InteractionRequest.Confirmation, Microsoft.Practices.Prism.Interactivity]])->

  0bf45ad0(System.EventHandler`1[[Microsoft.Practices.Prism.Interactivity.InteractionRequest.InteractionRequestedEventArgs, Microsoft.Practices.Prism.Interactivity]])->

  0bf4202c(Microsoft.Practices.Prism.Interactivity.InteractionRequest.InteractionRequestTrigger)->

  0bf41d90(System.Windows.Controls.Border)->

  0bf2b0c4(Eis.Silverlight.Library.Controls.MainContentContainerControl)->

  0bf2c21c(System.Windows.Controls.StackPanel)->

  0bf2c280(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bfc786c(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf34040(System.Windows.Controls.Border)->

  0bf340a4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bf340f0(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf33a04(System.Windows.Controls.StackPanel)->

  0bf33a68(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bf33ab4(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf33c6c(System.Windows.Controls.ItemsControl)->

  0bf33d44(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bf33d90(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf33dcc(System.Collections.Generic.Dictionary`2[[System.UInt32, mscorlib],[System.Windows.DependencyObject, System.Windows]])->

  0bf33e18(System.Collections.Generic.Dictionary`2+Entry[[System.UInt32, mscorlib],[System.Windows.DependencyObject, System.Windows]][])->

  0bf2a634(System.Windows.DataTemplate)->

  0bf29eb4(Eis.Silverlight.SecurityAdminModule.Views.UserAdministrationView)

DOMAIN(074A08E0):HANDLE(Pinned):59212f8:Root:  0cd24260(System.Object[])->

  0bd3b480(Eis.Silverlight.App)->

  0bd47ea4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bd47ef0(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bd47d2c(System.Windows.ResourceDictionary)->

  0bd47d84(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bd47dd0(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bd47cc8(MS.Internal.ResourceDictionaryCollection)->

  0bd47e0c(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bd47e58(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bd4374c(System.Windows.ResourceDictionary)->

  0bd43b0c(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bd47bd8(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bd47c64(System.Windows.DataTemplate)->

  0bf42580(Microsoft.Practices.Prism.Interactivity.InteractionRequest.PopupChildWindowAction)->

  0bf41d90(System.Windows.Controls.Border)->

  0bf2b0c4(Eis.Silverlight.Library.Controls.MainContentContainerControl)->

  0bf2c21c(System.Windows.Controls.StackPanel)->

  0bf2c280(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bfc786c(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf34040(System.Windows.Controls.Border)->

  0bf340a4(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bf340f0(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf33a04(System.Windows.Controls.StackPanel)->

  0bf33a68(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bf33ab4(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf33c6c(System.Windows.Controls.ItemsControl)->

  0bf33d44(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->

  0bf33d90(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->

  0bf33dcc(System.Collections.Generic.Dictionary`2[[System.UInt32, mscorlib],[System.Windows.DependencyObject, System.Windows]])->

  0bf33e18(System.Collections.Generic.Dictionary`2+Entry[[System.UInt32, mscorlib],[System.Windows.DependencyObject, System.Windows]][])->

  0bf2a634(System.Windows.DataTemplate)->

  0bf29eb4(Eis.Silverlight.SecurityAdminModule.Views.UserAdministrationView)

 

 

 

ksirmons replied on Thursday, January 06, 2011

Moving all of the DataTemplates from inline into the usercontrol.resources appears to fix the issue I was seeing.  (REF: http://forums.silverlight.net/forums/p/171739/389243.aspx)

My Views and ViewModels are now being GC'ed

Thank you,

Keith

Copyright (c) Marimer LLC