View Single Post
  #2 (permalink)  
Old April 30th, 2008, 11:51 AM
BrianWren BrianWren is offline
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

I'm not surprised that GC.Collect() has no effect. The GC runs automatically when space is needed. If collection could fix the problem it would be automatically done for you through that methodology.

It certainly appears to me that you have a memory leak. I have not addressed anything like this, but in thinking about what I would do if this happened to me (in addition to posting a question on WROX P2P, which I certainly would do—as you have), is add a reporting mechanism (to be removed once the problem is solved), and use APIs or the functionality of .NET to report memory stats when you anticipate consuming memory, and where you anticipating reclaiming memory, to see if you can detect an imbalance.

Perhaps—without actually determining the culprit—loading the DLL just once, and adding a re-initialization method to be used prior to each loop will make you “leak” the memory just once, which apparently is not a problem (since the error isn’t fatal until after 300,000 iterations).