开发者

Memory Leak when using Silverlight's TimePickers in MVVM application

In our Silverlight MVVM application we're struggling for some time with the Silverlight Toolkit TimePicker. Using it stops the View in which is used the TimePicker to be garbage collected. When I open and close 5 times the same view, there are 5 copies of the View in the memory.

Former problems with memory leaks we alredy had with KeyTriggers with an MVVM_Light:EventToCommand inside. This problem was solved by detaching the trigger in code behind by using the name of the KeyTrigger.

Using the WinDbg tool we can see that after closing the View there are references on the View (and of course also the ViewModel) from the TimePicker. My question is now, whether it is possible in some way to detach the particular TimePicker's KeyTrigger to solve this problem? Or if someone had already experience in using the TimePicker, there is another way to prevent the memory leak?

Thank you for your help!!

PS: Here is the output of WinDbg's !gcroot command of one View:

    DOMAIN(07E099E8):HANDLE(Pinned):39b12f8:Root:  0bd74260(System.Object[])->
  0ad8a2d0(System.Collections.Generic.Dictionary`2[[System.IntPtr, mscorlib],[System.Object, mscorlib]])->
  0c0dc6e8(System.Collections.Generic.Dictionary`2+Entry[[System.IntPtr, mscorlib],[System.Object, mscorlib]][])->
  0b6fa01c(System.Windows.Controls.Border)->
  0b6fa080(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
      0b6fa0cc(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  0b6f985c(System.Windows.Controls.Grid)->
  0b6f98c0(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
  0b6f9f90(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  0b6f9564(System.Windows.Controls.ContentControl)->
  0b6f97c8(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]])->
  0b6f9814(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]][])->
  0b6f97b4(MS.Internal.ModifiedValue)->
  0b6f9754(System.Windows.TemplateBindingExpression)->
  0b6f61a0(System.Windows.Controls.TimeUpDown)->
  0b6f874c(System.EventHandler`1[[System.Windows.Controls.UpDownParseErrorEventArgs, System.Windows.Controls.Input.Toolkit]])->
  0b49f9b4(System.Windows.Controls.TimePicker)->
  0b49fef4(System.Windows.DataContextChangedEventHandler)->
  0b49fea0(System.Windows.Data.BindingExpression)->
  0b44ff48(MyProject.ViewModel.MyV开发者_如何转开发iewModel)->
  0b450514(GalaSoft.MvvmLight.Command.RelayCommand`1[[System.String, mscorlib]])->
  0b707b1c(System.EventHandler)->
  0b4a7f84(GalaSoft.MvvmLight.Command.EventToCommand)->
  0b4a7c2c(System.Windows.DOCollection)->
  0b4a7bcc(System.Windows.Interactivity.TriggerActionCollection)->
  0b4a7b5c(Microsoft.Expression.Interactivity.Input.KeyTrigger)->
  0b4a4704(System.Windows.DOCollection)->
  0b4a5b8c(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyObject, System.Windows],[System.Object, mscorlib]])->
  0b4a84b0(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyObject, System.Windows],[System.Object, mscorlib]][])->
  0b4a7118(Microsoft.Expression.Interactivity.Input.KeyTrigger)->
  0b4a732c(System.Collections.Generic.Dictionary`2[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]])->
  0b4a7378(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.DependencyProperty, System.Windows],[System.Windows.EffectiveValueEntry, System.Windows]][])->
  0b70f5f4(MS.Internal.ModifiedValue)->
  0b4a2eb0(System.Windows.Controls.DataGrid)->
  0b7059e4(System.Windows.Controls.ScrollContentPresenter)->
  0b705a54(MS.Internal.Controls.ScrollData)->
  0b4a2bb8(System.Windows.Controls.ScrollViewer)->
  0b49b70c(System.Windows.Controls.Grid)->
  0b4a8b50(System.Windows.Controls.Grid)->
  0b48ebb0(System.Windows.Controls.Grid)->
  0b48ec14(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
  0b492f3c(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  0b49b4b0(System.Windows.Controls.Grid)->
  0b49b514(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
  0b49b560(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  0b493a28(System.Windows.Controls.Grid)->
  0b4947a8(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
  0b4aa2f4(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  0b498900(System.Windows.Controls.Grid)->
  0b49912c(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])->
  0b499178(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])->
  0b498ad4(System.Windows.Controls.TextBox)->
  0b498b58(MS.Internal.CoreTypeEventHelper)->
  0b498d20(System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]])->
  0b498d6c(System.Collections.Generic.Dictionary`2+Entry[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]][])->
  0b498d10(MS.Internal.CoreTypeEventHelper+EventAndDelegate)->
  0b498cd8(System.Windows.Input.KeyEventHandler)->
  0ae3cf10(MyProject.Views.MyView)


Visual Studio 2010 SP1 support profiling for Silverlight. You can us this utiilty and get the best out of it.


Try the Antz memory profiler (RedGate) and profile your app. It will give you all the info you need to determine why it's remaining in memory. Possibly an event handler not getting cleaned up?

I've solved so many memory leaks using their profiler. It's amazing the stuff you have to clean up yourself.


There is memory leak with special using KeyTrigger and Popup, and MS will not fix it near future.

The problem does not occur when Window is used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜