locked
Memory leak when using commands RRS feed

  • Question

  • Dear Sirs,

    Is there any fix for the memory leak when using commands in Silverlight 5? If Not How should we handle this problem, any work around? Do you have a VB.Net and C# Example of how to fix this?

    Thanks,

    Frank Hodgson

    Tuesday, March 29, 2016 9:25 PM

Answers

  • Thanks for your help Guys, it was the context menu that was causing the problems, found a solution in this post

    stackoverflow.com/questions/16815216/cant-get-recommended-fix-for-silverlight-contextmenu-memory-leaks-to-work

    Saturday, April 2, 2016 4:13 PM

All replies

  • Hi Frank Hodgson,

    Please check whether your Silverlight 5 version is the latest version first. The latest version should be 5.1.41212.0. If not, please upgrade it.

    If it is the latest version, please share some code snippet about the memory leak problem in your code. It can help us reproduce your problem in our side.

    In addition, please refer to following threads which about the Memory Leak problem in Silverlight application. There has some work around, please try with them to check whether your problem can be fixed.

    https://social.msdn.microsoft.com/Forums/silverlight/en-US/34d85c3f-52ea-4adc-bb32-8297f5549042/command-binding-memory-leak?forum=silverlightbugs

    Below one is the ICommand Memory Leak problem in WPF application, I think it should also applicable to Silverlight application. Hope that can help you.

    http://stackoverflow.com/questions/12919288/icommand-binding-causing-ui-memory-leak-in-wpf-application

    Best Regards,
    Weiwei

    Wednesday, March 30, 2016 1:35 AM
  • If you use mvvmlight, then RelayCommand uses weak events for it's commands.

    You don't need to unsubscribe them manually because they don't retain a strong reference.

    Bindings use weak events.

    So my suggestion would not be to work around, use mvvmlight relaycommand.

    https://msdn.microsoft.com/en-gb/magazine/dn237302.aspx?f=255&MSPPError=-2147217396

    You can use nuget to add mvvmlightlibs to an existing Silverlight project.

    Messenger is also very useful BTW.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Wednesday, March 30, 2016 3:38 PM
  • Hi Andy,

    I have tried using the relay command without using the other functionality of MVVMLight but this does not solve my problem. I am using a context menu in a Xaml graphical Model with lots of nodes, this context menu is defined for all the nodes. And in this context menu I have defined menu items wich use the relaycommand to do something. I have tried the solution from WeiWei some weeks ago and now the Relaycommand solution but my app keeps leaking memory. See Memory profile below

    Thursday, March 31, 2016 4:54 PM
  • As I explained, relaycommand doesn't leak in the same way as an icommand could do, because it isn't a hard reference.

    So I wonder whether the commands are actually your problem.

    At least in terms of binding.

    You could use a trial version of ants memory profiler to work out exactly what code is leaking. It's free for 14 days.

    http://www.red-gate.com/products/dotnet-development/ants-memory-profiler/


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Friday, April 1, 2016 2:23 PM
  • Thanks for your help Guys, it was the context menu that was causing the problems, found a solution in this post

    stackoverflow.com/questions/16815216/cant-get-recommended-fix-for-silverlight-contextmenu-memory-leaks-to-work

    Saturday, April 2, 2016 4:13 PM