<?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>Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx</link><description>Problem: A customer called in. They had a Web Service running on a single IIS6. Memory usage would slowly increase and not be released. As a workaround they'd currently set the application pool to recycle at 500 MB, causing a few failed requests upon</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#7839428</link><pubDate>Thu, 21 Feb 2008 19:18:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7839428</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;I just wanted to say that this is the first time I have seen someone take time out to actually explain the process of debugging a memory leak. It was very useful, thanks.&lt;/p&gt;
&lt;p&gt;The only thing else I wanted to comment on was the section of code in &amp;quot;What causes the leak?&amp;quot;, and the fact that it is not clear (to me at least, sorry if I am being dense!) what the trace is actually inferring there. What bit should I be looking at for?&lt;/p&gt;
&lt;p&gt;Possible to highlight the offending bits please? That would be a great help on my journey.&lt;/p&gt;
&lt;p&gt;Thanks again.&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#7846050</link><pubDate>Fri, 22 Feb 2008 11:52:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7846050</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you look at the top of the trace you see that we end up in the third party component. &amp;nbsp;Before that we're using the System.Data namespace, but eventually we find ourselves in the Company.App.Server.DAL.DAO namespace. THIS is the part where we actually can make a change. The leak happens in the third party dll, but it's a fairly widely used component, so it could be that we've come across a known issue. Changing the way we call the data connector in our code might fix the situation.&lt;/p&gt;
&lt;p&gt;For example: If there is a known possibility of a leak when you call a certain function with parameters X, Y &amp;amp; Z, then we might be able to resolve it by calling the function with parameters X &amp;amp; Y only.&lt;/p&gt;
&lt;p&gt;If there is no such sollution, then we at least have sufficient information to prove to the third party that there is a problem in their product. &lt;/p&gt;
&lt;p&gt;This is actually quite common, and I believe there is a value in showing an example where the problem is actually beyond our reach. Being able to say that you KNOW the problem lies within a certain component rather than you THINK definitively gives you the upper hand.&lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#7939554</link><pubDate>Fri, 29 Feb 2008 05:15:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7939554</guid><dc:creator>baal</dc:creator><description>&lt;p&gt;i have the same problem of your customer,Memory usage would slowly increase and not be released,set the application pool to recycle at 500 MB,&lt;/p&gt;
&lt;p&gt;this article is so great that i want kiss you. but when i finish read,i think this article is a big head and small end.&lt;/p&gt;
&lt;p&gt;third-party problems! &lt;/p&gt;
&lt;p&gt;in my app, no third-party, but i think the problem may be that two parts ,one is the connection to db with some resource not disposed, two is the file upload module with some resource not disposed.&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#7943443</link><pubDate>Fri, 29 Feb 2008 09:47:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7943443</guid><dc:creator>baal</dc:creator><description>&lt;p&gt;when I got the dump file as your step, click &amp;quot;Start Analysis&amp;quot;, when &amp;nbsp;&amp;quot;loading leak track info. please wait&amp;quot;, it looks like dead. does this really need so much time and I just wait? &lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#7944680</link><pubDate>Fri, 29 Feb 2008 11:45:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7944680</guid><dc:creator>baal</dc:creator><description>&lt;p&gt;can you give more ,write some more about native leak?&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8000641</link><pubDate>Mon, 03 Mar 2008 14:53:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8000641</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Hi Baal,&lt;/p&gt;
&lt;p&gt;Native leaks are always a lot more difficult to track than the managed ones.&lt;/p&gt;
&lt;p&gt;To identify where in your code things go wrong I'd do the following:&lt;/p&gt;
&lt;p&gt;1. Use leak track to identify the assemblies that are growing abnormally. &lt;/p&gt;
&lt;p&gt;2. Investigate the memory usage report and look at the sample call stacks.&lt;/p&gt;
&lt;p&gt;3. Cross-reference the callstacks with your code to identify what sections are allocating memory without releasing it properly.&lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8001402</link><pubDate>Mon, 03 Mar 2008 15:52:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8001402</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Hi Johan,&lt;/p&gt;
&lt;p&gt;I truely love your blog and find it very usefull.&lt;/p&gt;
&lt;p&gt;How it is possible that dump size is 300MB less then size indicated by perfmon? Could it be caused by &amp;quot;memory holes&amp;quot; in the native memory?&lt;/p&gt;
&lt;p&gt;What would you say about the following scenario:&lt;/p&gt;
&lt;p&gt;I have a WinForms app running for 14 hours without user interaction. &lt;/p&gt;
&lt;p&gt;Dump #1, at the beginning, size is 1020MB.&lt;/p&gt;
&lt;p&gt;Dump #2, at the end, size is 1080MB.&lt;/p&gt;
&lt;p&gt;GC Heap Size stays at ~200MB at both dumps.&lt;/p&gt;
&lt;p&gt;Perfmon shows a linear increase in private bytes, from 600MB to 800MB, and increase in virtual bytes from 1300MB to 1400MB.&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8021023</link><pubDate>Tue, 04 Mar 2008 10:17:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8021023</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Hi David,&lt;/p&gt;
&lt;p&gt;I can't really say what the root cause is without investigating the dumps. If I had to guess I'd say that streaming is a likely cause of the inconsistency.&lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8023568</link><pubDate>Tue, 04 Mar 2008 12:57:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8023568</guid><dc:creator>baal</dc:creator><description>&lt;p&gt;Hi Johan,&lt;/p&gt;
&lt;p&gt;Can you help me investigate my dump file?&lt;/p&gt;
&lt;p&gt;the file is here: &lt;a rel="nofollow" target="_new" href="http://www.sula.cn/soft/w3wpdump.zip"&gt;http://www.sula.cn/soft/w3wpdump.zip&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;then write some more for the article?&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8025869</link><pubDate>Tue, 04 Mar 2008 15:41:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8025869</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Hi Baal,&lt;/p&gt;
&lt;p&gt;I'd recommend contacting your local Microsoft support representative and open up a regular support incident for this.&lt;/p&gt;
&lt;p&gt;Thanks / Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8048430</link><pubDate>Wed, 05 Mar 2008 11:11:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8048430</guid><dc:creator>David</dc:creator><description>&lt;p&gt;I want to analyze the dump myself. How would you start doing so in the described scenario ? &lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8049971</link><pubDate>Wed, 05 Mar 2008 12:48:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8049971</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Hi David,&lt;/p&gt;
&lt;p&gt;Well, if you're not running the .NET framework I'd begin by running it through Debug Diag as described in the article above.&lt;/p&gt;
&lt;p&gt;If it's managed I'd use windbg. For usefulo commands please refer to the &amp;quot;Debugging School&amp;quot;-section to the left as well as &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/johan/archive/2007/01/11/i-am-getting-outofmemoryexceptions-how-can-i-troubleshoot-this.aspx"&gt;http://blogs.msdn.com/johan/archive/2007/01/11/i-am-getting-outofmemoryexceptions-how-can-i-troubleshoot-this.aspx&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8052382</link><pubDate>Wed, 05 Mar 2008 18:11:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8052382</guid><dc:creator>David</dc:creator><description>&lt;p&gt;OK, but I am interested to know how streaming can cause such an inconsistency.. My application does use some kind of streaming.&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8052606</link><pubDate>Wed, 05 Mar 2008 18:43:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8052606</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Like I said, It's not easy to guess without seeing it for myself.&lt;/p&gt;
&lt;p&gt;I know Memory Mapped Files can cause this type of situaiton. (Sorry for the &amp;quot;streaming&amp;quot; confusion.) There might be other possible reasons that I just can't think of right now.&lt;/p&gt;
&lt;p&gt;Does the dump look okay in all the other aspects or does it appear corrupt?&lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8505518</link><pubDate>Thu, 15 May 2008 03:06:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8505518</guid><dc:creator>Martin Kulov</dc:creator><description>&lt;p&gt;I would bet that there is some caching implementation in the thrid party component.&lt;/p&gt;
&lt;p&gt;Did you get any result of the actual problem?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Martin&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#8513310</link><pubDate>Fri, 16 May 2008 17:39:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8513310</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;I find that very likely as well. I was hoping to find out the root cause eventually, but unfortunately I still do not know what it was... :(&lt;/p&gt;
&lt;p&gt; / Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#9029355</link><pubDate>Sun, 02 Nov 2008 20:19:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9029355</guid><dc:creator>Nikhil</dc:creator><description>&lt;p&gt;I have a native memory leak while running the ASP app on windows 2008 server under IIS6 management compatibility mode... But when I do the analysis using the steps mentioned by you, The memory size mentioned is in TBytes!! I have done this a Lot of times with a lot of options - any suggestions ?&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#9873951</link><pubDate>Tue, 18 Aug 2009 15:02:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9873951</guid><dc:creator>Ling</dc:creator><description>&lt;p&gt;so how can we get the callstack of the leak function? I wrote a .net program, and allocate several large arrays without releasing them for test. I used the DebugDiag to monitor and analyze, finally i got the report. And it tells me that the leak function is mscorwks!EEVirtualAlloc+119, however, it doesnot show me any call stack sample. what's going on? could you please give me some suggestions?&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#9904492</link><pubDate>Wed, 07 Oct 2009 21:05:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9904492</guid><dc:creator>Denny Ferrassoli</dc:creator><description>&lt;p&gt;Johan thank you for this post, it's been very helpful!&lt;/p&gt;
&lt;p&gt;I have a similar issue but my callstack only shows memory addresses like below:&lt;/p&gt;
&lt;p&gt;Function &amp;nbsp; Source &amp;nbsp; Destination &lt;/p&gt;
&lt;p&gt;0x79E8C582 &amp;nbsp; &amp;nbsp; &amp;nbsp;0x79E717B4 &lt;/p&gt;
&lt;p&gt;0x79F8C96F &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;kernel32!BaseThreadStart+34 &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I was expecting some .NET callstack info but as you can see there is none :) Do you know how I can further investigate this? Thanks&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#9904784</link><pubDate>Thu, 08 Oct 2009 10:49:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9904784</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;Hi Denny!&lt;/p&gt;
&lt;p&gt;It's not too much to work with, but if debug diag is reporting that this is the callstack hogging memory from your application I'd look into just how many threads you have running in the application. (Use ~* in windbg)&lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item><item><title>re: Walkthrough - Troubleshooting a native memory leak</title><link>http://blogs.msdn.com/johan/archive/2008/02/21/walkthrough-troubleshooting-a-native-memory-leak.aspx#9904797</link><pubDate>Thu, 08 Oct 2009 11:37:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9904797</guid><dc:creator>JohanS</dc:creator><description>&lt;p&gt;@Ling: (Sorry about the late reply)&lt;/p&gt;
&lt;p&gt;Debug diag doesn't show you managed callstacks. You'll have to use windbg for that.&lt;/p&gt;
&lt;p&gt;Open up the same dump in windbg, go to the thread identified by debug diag and use !clrstack to see the managed callstack.&lt;/p&gt;
&lt;p&gt;/ Johan&lt;/p&gt;
</description></item></channel></rss>