Memory leak with Interaction Triggers in MVVM Light Toolkit Silverlight -


visual studio 2012 project memory leak

hello! i've found memory leak when using interaction triggers in mvvm light toolkit. use xaml

<usercontrol x:class="memoryleaktest.mainpage"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"          xmlns:ignore="http://www.ignore.com"          mc:ignorable="d ignore"          xmlns:i="clr-namespace:system.windows.interactivity;assembly=system.windows.interactivity"             xmlns:mvvm="clr-namespace:galasoft.mvvmlight.command;assembly=galasoft.mvvmlight.extras.sl5"          x:name="control"          datacontext="{binding main, source={staticresource locator}}">  <grid x:name="layoutroot">      <itemscontrol itemssource="{binding leakobjects}">         <itemscontrol.itemspanel>             <itemspaneltemplate>                 <stackpanel/>             </itemspaneltemplate>         </itemscontrol.itemspanel>         <itemscontrol.itemtemplate>             <datatemplate>                 <border  width="300" borderthickness="6" borderbrush="blueviolet" cornerradius="3">                     <grid background="{binding colorbrush}" >                         <stackpanel>                             <button command="{binding elementname=control, path=datacontext.command}"  width="100" height="40" content="tryck!">                                 <i:interaction.triggers>                                     <i:eventtrigger eventname="click">                                         <mvvm:eventtocommand command="{binding elementname=control, path=datacontext.command}" commandparameter="{binding}"/>                                     </i:eventtrigger>                                 </i:interaction.triggers>                             </button>                             <textblock text="{binding text}"/>                         </stackpanel>                     </grid>                 </border>             </datatemplate>         </itemscontrol.itemtemplate>     </itemscontrol> </grid> 

and rebind list leakobjects creates new items. old items (xaml) buttons , text blocks still in memory , doesn't gc.

if write

<button command="{binding elementname=control, path=datacontext.command}"  width="100" height="40" content="press!"/> 

and use buttons command parameter there no memory leak if use the

<i:interaction.triggers>      <i:eventtrigger eventname="click">           <mvvm:eventtocommand command="{binding elementname=control, path=datacontext.command}" commandparameter="{binding}"/>      </i:eventtrigger>  </i:interaction.triggers> 

there major leak.

the problem there no command parameters on grids etc.

the project in link has simple project demonstrating problem.

is there way circumvent memory leak? maybe i'm using wrong.

it crucial find way fix because memory leak on our application.

i've experienced leak well. i've solved not using eventtocommands , rather using plain event handlers , calling commands these methods in page code-behind. it's not clean, works , page garbage collected expected.
or use invokecommandaction instead, works me.
http://www.dotnetpatterns.net/entries/21-memory-leak-issue-with-eventtocommand-passing-binding-to-relaycommand


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -