title: How do I avoid a memory leak with LINQ-To-SQL?
body: <p>I have been having some issues with LINQ-To-SQL around memory usage.  I'm using it in a Windows Service to do some processing, and I'm looping through a large amount of data that I'm pulling back from the context.  Yes - I know I could do this with a stored procedure but there are reasons why that would be a less than ideal solution.</p>
  
  <p>Anyway, what I see basically is memory is not being released even after I call <code>context.SubmitChanges()</code>.  So I end up having to do all sorts of weird things like only pull back 100 records at time, or create several contexts and have them all do separate tasks.  If I keep the same <code>DataContext</code> and use it later for other calls, it just eats up more and more memory.  Even if I call <code>Clear()</code> on the "<code>var tableRows</code>" array that the query returns to me, set it to null, and call <code>SYstem.GC.Collect()</code> - it still doesn't release the memory.</p>
  
  <p>Now I've read some about how you should use <code>DataContexts</code> quickly and dispose of them quickly, but it seems like their ought to be a way to force the context to dump all its data (or all its tracking data for a particular table) at a certain point to guarantee the memory is free.</p>
  
  <p>Anyone know what steps guarantee that the memory is released?</p>