<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx</link><description>One of the axioms of working with managed code is that since you&amp;#8217;re using managed code, you don&amp;#8217;t have to worry about memory leaks. 
 This can&amp;#8217;t be further from the truth. It&amp;#8217;s totally possible to write code that leaks memory</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#136039</link><pubDate>Thu, 20 May 2004 18:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:136039</guid><dc:creator>Ethan Henry</dc:creator><description>This is kind of funny to read... I co-wrote an article about this back in, oh, 2000. Though you might have skipped it - it was an article about Java.&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://www.ddj.com/documents/s=888/ddj0002l/0002l.htm"&gt;http://www.ddj.com/documents/s=888/ddj0002l/0002l.htm&lt;/a&gt;&lt;br&gt;&lt;br&gt;You'll have to register to get at it though.&lt;br&gt;&lt;br&gt;Anyway, this problem is fairly common in Java apps, especially J2EE apps. There are &amp;quot;memory profiling&amp;quot; tools like JProbe and OptimizeIt that can help track them down. I used to work with the JProbe team (now part of Quest Software).&lt;br&gt;&lt;br&gt;We called these kinds of problems &amp;quot;loitering objects&amp;quot; to distinguish them from traditional C++ memory leaks where memory can't be freed because the pointer has been lost.&lt;br&gt;&lt;br&gt;Managed code development is very, very similar to Java development. I highly recommend some of the advanced Java development books to people getting into managed code for the first time. Many concepts are identical.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=136039" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135914</link><pubDate>Thu, 20 May 2004 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135914</guid><dc:creator>BJ Herrington</dc:creator><description>Ya, that's what i was refering to with 'COM Release'.  I made sure to call it each time I was finished with an ADO object the second time around, but even doing that the GC liked to keep them around for way too long considering the memory the application was consuming.  Even on the server I ran the app on (4 gig ram) it crashed well before finishing.&lt;br&gt;&lt;br&gt;Going for a 3rd try, I called GC.Collect at the end of every proc that used ADO, and even tho it still ate up quite a lot of memory, it did at least finish.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135914" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135911</link><pubDate>Thu, 20 May 2004 15:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135911</guid><dc:creator>Larry Osterman</dc:creator><description>Absolutely BJ.  A very good point.&lt;br&gt;&lt;br&gt;Btw, you do know about System.InteropServices.Marshal.ReleaseComObject(), right?&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135911" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135865</link><pubDate>Thu, 20 May 2004 14:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135865</guid><dc:creator>BJ Herrington</dc:creator><description>This is especially true when dealing with COM Interop in managed code.  I once rewrote some old vb6 code in vb.net using ado.  Of course, at the time, I didn't realize that the ado interop was *not* the ado.net lib.  Long story short, I created about 50,000 ado objects w/o a single COM Release.&lt;br&gt;&lt;br&gt;Even later when I rewrote that part, I had to call GC.Collect() very often to keep the app from blowing up to ~800 meg.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135865" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135687</link><pubDate>Thu, 20 May 2004 08:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135687</guid><dc:creator>thomas woelfer</dc:creator><description>Larry,&lt;br&gt;&lt;br&gt;thats why i'd really like to see a tool in visual studio that shows the interconnections of allocated objects.... &lt;br&gt;&lt;br&gt;WM_THX&lt;br&gt;thomas woelfer&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135687" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135398</link><pubDate>Wed, 19 May 2004 22:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135398</guid><dc:creator>Larry Osterman</dc:creator><description>My app was consuming 1.5G of memory before I realized what was wrong.  While you're right that it's not TECHNICALLY a memory leak, it might as well have been one.&lt;br&gt;&lt;br&gt;And some of the subtle bugs I mentioned above can result in situations that are indistinguishable from a memory leak.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135398" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135373</link><pubDate>Wed, 19 May 2004 21:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135373</guid><dc:creator>Ryan Gregg</dc:creator><description>But this isn't really a memory leak in the traditional sense, it's just a bad piece of code sucking up more memory than you might otherwise think is correct.  The memory isn't being lost like a traditional memory leak, and the GC will collect it when everything is disposed, right?&lt;br&gt;&lt;br&gt;Say, if you dispose the document that all these nodes are being created on.  Right?  Or am I wrong in thinking that and this really is a leak in the traditional sense?&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135373" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135357</link><pubDate>Wed, 19 May 2004 21:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135357</guid><dc:creator>Jerry Pisk</dc:creator><description>Josh you're right, enumerators don't have to reset on a collection change and XmlNodeList is one of those that don't. Cool :) I actually like features that let you shoot yourself in the foot if you want to.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135357" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135278</link><pubDate>Wed, 19 May 2004 19:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135278</guid><dc:creator>dudetron</dc:creator><description>we have this problem all the time in GDI+ when creating dynamic System.Drawing.Images at a high rate. calling Dispose() on the image is not sufficient..GC.Collect() has to be called or one encounters tremendous pile-up, again not technically a 'leak' as mentioned above...&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135278" width="1" height="1"&gt;</description></item><item><title>re: Managed Code can't have memory leaks, right?</title><link>http://blogs.msdn.com/b/larryosterman/archive/2004/05/19/135211.aspx#135253</link><pubDate>Wed, 19 May 2004 19:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:135253</guid><dc:creator>Larry Osterman</dc:creator><description>Whoops :)  I'll fix that asap.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=135253" width="1" height="1"&gt;</description></item></channel></rss>