ContextMenu subscribes MouseMove event in ContextMenu.InitializeRootVisual, but it won't unsubscribe it, and it don't use WeakEvent. So it won't be GCed after it is unloaded. I verified the leak in Windbg, sample !gcroot result:
DOMAIN(063DF7F0):HANDLE(Pinned):6b612f8:Root: 07d64260(System.Object[])->
06d96964(SAPStudio.I264Player.SilverlightGui.MainPage_3)->
06d96a2c(MS.Internal.CoreTypeEventHelper)->
06d96a98(System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]])->
07907da0(System.Collections.Generic.Dictionary`2+Entry[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]][])->
0765c110(MS.Internal.CoreTypeEventHelper+EventAndDelegate)->
0765c0d8(System.Windows.Input.MouseEventHandler)->
*** 0764ce5c(System.Windows.Controls.ContextMenu) ***->
0764de04(System.Windows.Controls.ItemCollection)->
07650ee0(System.Collections.Generic.Dictionary`2[[System.Windows.UIElement, System.Windows],[System.Object, mscorlib]])->
07650f2c(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.UIElement, System.Windows],[System.Object, mscorlib]][])->
0764ec38(System.Windows.Controls.MenuItem)->
0764ecc0(MS.Internal.CoreTypeEventHelper)->
0764f4d8(System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]])->
0764f524(System.Collections.Generic.Dictionary`2+Entry[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]][])->
0764f4c8(MS.Internal.CoreTypeEventHelper+EventAndDelegate)->
0764f490(System.Windows.RoutedEventHandler)->
0764f318(System.Windows.Data.BindingExpression)->
0764f144(SAPStudio.I264Player.SilverlightGui.Interactivity.ClipboardCommands.CopyCommand)
Comments: ** Comment from web user: Xiaoyue2838 **
DOMAIN(063DF7F0):HANDLE(Pinned):6b612f8:Root: 07d64260(System.Object[])->
06d96964(SAPStudio.I264Player.SilverlightGui.MainPage_3)->
06d96a2c(MS.Internal.CoreTypeEventHelper)->
06d96a98(System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]])->
07907da0(System.Collections.Generic.Dictionary`2+Entry[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]][])->
0765c110(MS.Internal.CoreTypeEventHelper+EventAndDelegate)->
0765c0d8(System.Windows.Input.MouseEventHandler)->
*** 0764ce5c(System.Windows.Controls.ContextMenu) ***->
0764de04(System.Windows.Controls.ItemCollection)->
07650ee0(System.Collections.Generic.Dictionary`2[[System.Windows.UIElement, System.Windows],[System.Object, mscorlib]])->
07650f2c(System.Collections.Generic.Dictionary`2+Entry[[System.Windows.UIElement, System.Windows],[System.Object, mscorlib]][])->
0764ec38(System.Windows.Controls.MenuItem)->
0764ecc0(MS.Internal.CoreTypeEventHelper)->
0764f4d8(System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]])->
0764f524(System.Collections.Generic.Dictionary`2+Entry[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]][])->
0764f4c8(MS.Internal.CoreTypeEventHelper+EventAndDelegate)->
0764f490(System.Windows.RoutedEventHandler)->
0764f318(System.Windows.Data.BindingExpression)->
0764f144(SAPStudio.I264Player.SilverlightGui.Interactivity.ClipboardCommands.CopyCommand)
Comments: ** Comment from web user: Xiaoyue2838 **
The source code in Silverlight SDK uses a defferent PublicKeyToken, after replacing reference to the modified System.Windows.Controls.Input.Toolkit.dll the build is failed. The error message is The type 'System.Windows.Controls.ExpandDirection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Controls.Toolkit, Version=5.0.5.0, Culture=neutral, PublicKeyToken=2c5c654d367bf4a7'. How to resolve this problem?