title: ASP.NET: Large memory leak.. Where is it? DB? Updatepanels? No disposables?
body: <p>I have been developing a quite large application, and I uploaded it to my server some days ago. Now I have found out it has several memory leaks - Uh oh.
  My server is running Windows Server 2008 on 1GB ram. When I have 0 people online, only 550-600mb is used. When one people comes online the memory starts skyrocketing, and if 3-4 people are online all 1GB ram is used.</p>
  
  <p>The application is made in ASP.NET with AJAX. It has many updatepanels which runs every second and quite a lot of javascript. It uses 5-7 sessions at all times. I use LINQ to SQL as database communication.</p>
  
  <p>I tried perfmon.exe on my server, and I found:</p>
  
  <ul>
  <li>Gen 0 collections goes from 0% to
  100% within minutes </li>
  <li>Gen 1 collections
  goes from 0% to 50% within 5 minutes</li>
  <li>Gen 2 is very close to 0% at all
  times </li>
  <li>Total heap bytes goes up to
  100% very fast</li>
  </ul>
  
  <p>I also ran an analysis of my program with Visual Studio. 8% Of my total runtime is done in .ToList() methods, which properly is caused by LINQ to SQL.</p>
  
  <p><em><strong>My theories....</em></strong></p>
  
  <p><strong>(1) Linq to SQL dataContext</strong></p>
  
  <p>This might be a crazy thing to do, but: In my data access layer I have a load of methods:</p>
  
  <ul>
  <li>AddSomethingToDatabase();</li>
  <li>AddSomethingElseToDatabase();</li>
  <li>DeleteSomethingFromDatabase();</li>
  </ul>
  
  <p>Each of these has the following initialization:</p>
  
  <pre><code>GameDataContext db = new GameDataContext();
  </code></pre>
  
  <p>Which means the above statement runes nearly every second or more. </p>
  
  <p><strong>(2) No objects implement IDisposable</strong></p>
  
  <p>I have to be honest: I have never worked with IDisposable. As far as I have read, this might be a problem.</p>
  
  <p>Also, if this is the leak, which classes should implement it? I do not have any I/O work or others, only the DataContext.</p>
  
  <p><strong>(3) Loads of UpdatePanels and jQuery</strong></p>
  
  <p>I have some fear loads of updatepanels can give problems with performance, but I do not know how to check it.</p>
  
  <hr>
  
  <p>So my question is: Any ideas on what the memory leak could be? Any ideas on how to find the memory leak? And any ideas on how to solve it?</p>
  
  <p>I would love to hear from someone who has experience with the situation above! </p>
  
  <p>Thanks,
  Lars</p>