Garbage collection while running tests
I have a fairly large test project with about 1200 unit tests in it, that, when I run all of the tests, the memory usage for vstesthost.exe grows to over 450 MB. This causes a problem on some of our machines that only have 1GB of RAM. I have tried after every test to dispose everything, set everything to null, and even call GC.Collect(), but the memory still continues to climb until the test run is complete. Is there a way to get the test run to release it's memory resources as the test run goes on, or is this a bug?
Any help is appreciated.
Thanks
[577 byte] By [
NewDawn] at [2007-12-20]
Hello!
Can you reproduce this issue with 1200 empty Unit Tests? Can you please tell us what the Unit Tests do. There are some scenarios when .NET keeps memory, e.g. you have .NET remoting objects with null lease.
Also to find which test(s) may cause memory issues you can try to do the following: in TestCleanup add a line like: GC.Collect(); Console.Write("{0:000000}k", GC.GetTotalMemory(false) / 1000);
Then in Results window right click->Add/Remove columns, make sure that Output(StdOut) is checked. Then sort by Output(StdOut) column.
If it's possible, please send your repro solution with all dependencies to us and we can take a look.
Thanks,
Michael Koltachev,
VSTS
Michael, thanks for the ideas. I won't be able to send you my solution, but here are some ideas about things that we do often in our tests.
First of all, we are not using any remoting objects in our application.
Almost every test reads in at least one Xml file into an XmlDocument.
Almost every test reads in a serialized DataSet from an Xml file to a DataSet.
Maybe half of the tests make a WebService call.
Would any of these things cause .NET to keep memory? I will see what I can do to reproduce it with empty tests.
Thanks for your help
If you use Xml and DataSet in correct way they should not leave leaked objects. Please make sure that if an object is IDisposable, you call Dispose for it. This is not required for some Database objects closed but I would do that just in case. Also please let us know what you found using empty unit tests and using my proposal for dumping GC memory.
Thank you,
Michael Koltachev,
VSTS