<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Will code like this cause memory leaks?</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Will code like this cause memory leaks?</description>
  <pubDate>Wed, 13 May 2026 00:09:13 -700</pubDate>
  <lastBuildDate>Mon, 03 Dec 2012 16:44:34 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=3830</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Will code like this cause memory leaks? : Unfortunately, memory leaks also...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3830&amp;PID=15324#15324</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 3830<br /><strong>Posted:</strong> 03-Dec-2012 at 4:44pm<br /><br />Unfortunately, memory leaks also occur if the subscriber lives longer than the publisher. With a .NET event both subscriber and publisher hold a strong&nbsp;reference&nbsp;to each other unless the subscriber is static. The above code is safe due to the use of a locally scoped lamba. It would be&nbsp;problematic&nbsp;if you made the event handler an instance method of the current class. In that case the EntityQueryOperation couldn't be garbage collected until your current class instance goes away.<br>]]>
   </description>
   <pubDate>Mon, 03 Dec 2012 16:44:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3830&amp;PID=15324#15324</guid>
  </item> 
  <item>
   <title>Will code like this cause memory leaks? :   The code as shown shouldn&amp;#039;t...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3830&amp;PID=15322#15322</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 3830<br /><strong>Posted:</strong> 03-Dec-2012 at 1:32pm<br /><br />The code as shown shouldn't cause a memory leak.&nbsp; The EntityQueryOperation here is short-lived, as is the event handling "subscriber" code.&nbsp; Memory leaks due to event handlers are said to occur when the publisher of the event lives longer than the subscriber.&nbsp;&nbsp; Here, the operation is the publisher, and if you aren't holding on to the returned EntityQueryOperation, shouldn't cause a leak.&nbsp;&nbsp; That said, the best way to determine if your application has leaks is to profile it.]]>
   </description>
   <pubDate>Mon, 03 Dec 2012 13:32:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3830&amp;PID=15322#15322</guid>
  </item> 
  <item>
   <title>Will code like this cause memory leaks? :   I noticed in one other place...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3830&amp;PID=15316#15316</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1264" rel="nofollow">katit</a><br /><strong>Subject:</strong> 3830<br /><strong>Posted:</strong> 30-Nov-2012 at 9:20pm<br /><br /><div>I noticed in one other place that some of my views in Silverlight weren't disposing because of event subscriptions.</div><div>&nbsp;</div><div>Now I'm really paranoid, there is a bunch of code like this laying around:</div><div><table width="99%"><tr><td><pre class="BBcode"></div><p>&nbsp;var query = this.EntityManager.SYNC_ASTTrailerQuery(trailerKey);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var op = query.ExecuteAsync();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; op.Completed += (s, args) =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args.CompletedSuccessfully &amp;&amp; onSuccess != null) onSuccess();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!args.HasError) return;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; args.MarkErrorAsHandled();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (onFail != null) onFail(args.Error);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return op;</p><div></pre></td></tr></table></div><div>&nbsp;</div><div>Should I fix it? Is this really going to cause leaks?</div>]]>
   </description>
   <pubDate>Fri, 30 Nov 2012 21:20:37 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3830&amp;PID=15316#15316</guid>
  </item> 
 </channel>
</rss>