Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

Commented Issue: InteractionRequestTrigger can cause memory leaks with some implementations. [8532]

$
0
0
<p>Hi,</p>
<p>I found a issue for Prism v4 - Silverlight 4 and WPF 4.</p>
<p>&#160;</p>
<p>InteractionRequestTrigger inherits System.Windows.Interactivity.EventTrigger.</p>
<p>The EventTrigger doesn't implement WeakEvent Pattern.</p>
<p>It creates a strong reference from event source.</p>
<p>&#160;</p>
<p>As a result, </p>
<p>InteractionRequestTrigger can cause memory leaks with some implementations.</p>
<p>&#160;</p>
<p>&#160;</p>
<p>For example, </p>
<p>&#160;</p>
<p>A View has a InteractionRequestTrigger that has ViewModel's InteractionRequest as SourceObject.</p>
<p>The ViewModel lives longer than the View.</p>
<p>In this case, the View is kept alive longer than intended.</p>
<p>&#160;</p>
<p>&#160;</p>
<p>Code sample is...</p>
<p>&#160;</p>
<p>// In a MainWindow</p>
<p>&#160;</p>
<p>/// &lt;summary&gt;</p>
<p>/// SubWindow's ViewModel that has a InteractionRequest.</p>
<p>/// This is MainWindow's instance member.</p>
<p>/// &lt;/summary&gt;</p>
<p>private SubWindowViewModel _vm;</p>
<p>&#160;</p>
<p>private void button1_Click(object sender, RoutedEventArgs e)</p>
<p>{</p>
<p> if (_vm == null)</p>
<p> {</p>
<p> _vm = new SubWindowViewModel();</p>
<p> }</p>
<p>&#160;</p>
<p> //Create SubWindow's instance that has InteractionRequestTrigger.</p>
<p> //And add ViewModel to it's DataContext.</p>
<p> var window = new SubWindow { DataContext = _vm };</p>
<p> </p>
<p> window.ShowDialog();</p>
<p>}</p>
<p>&#160;</p>
<p>//I expected that SubWindow could be garbage collected after it was closed, but it couldn't.</p>
<p>&#160;</p>
<p>## Same topic was created in &quot;Discussins&quot; by Mr. okazuki.</p>
<p>## http://compositewpf.codeplex.com/discussions/265154</p>
<p>&#160;</p>
<p>Thanks.</p>
Comments: ** Comment from web user: IliyaTretyakov **

Maybe the "DataContext = null" is the best solution for leaks and for now?
http://prisminteractionlack.codeplex.com/
WeakInteractionRequest - it's overwhelming.
It don't solve other troubles.
Sorry if I wrong.


Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>