You can use ants memory profiler to find mememory leaks in your .net code and therefore also in your test code. Using the nunit.exe (classic nunit gui) is the best way to do this. A how to:

1) Find a test that consumes memory by looking at the memory consumption of nunit.exe when you run it sequentially.
2) Fire up ants memory profiler and profile nunit.exe
3) Run your test once.
4) Make a snapshot
5) Run your test again
6) Make another snapshot

By comparing the snapshots you can see which objects were added by the 2nd run. How to link these objects to a memory leak is shown in this nice movie: http://www.red-gate.com/products/ants_memory_profiler/overview.htm
Basically it's all about breaking references to never collected (static?) objects.

For me it turned out I had a lot of IDisposable objects (which require you to call Dispose() when you are done) which were not disposed (or the dispose did not clean up all references). By breaking all references to static objects (or other GC-roots) the object will be collected when the garbage man comes around More about disposable here:http://www.eggheadcafe.com/articles/20050625.asp

  • No labels