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).
|