.netunit-testingnunitmemory-profilingants

How do I run a memory profiler on our test projects?


All,

Something's wrong with our test project throwing OOM exceptions, and I suspect the problem is us. We're holding references somehow and memory is never being released.

So, I'd like to run a memory profiler and see where this is happening.

Setting up a profiler tool is a simple matter of pointing the tool to nunit-console.exe and running our test project and taking a few snapshots.

Unfortunately, this doesn't work. I've tried both SciTech and demoed ANTS and both happily report that the NUnit console assembly/appdomain/whatever isn't growing. Great. The process in task manager has steadily grown to 450MB, but the memory profilers are reporting it hasn't grown at all.

Great.

I've googled, and I have seen some (tool-specific) simplistic instructions for how to deal with unit test projects. I've tried those things, and they didn't work. I've tried playing with NUnit's appdomain/assembly settings, thus far to no avail.

So.

Has anyone actually run a memory profiler against a test project (of any kind--we use NUnit, but I'd bet it's the same for any .NET automated testing framework) successfully? For any .NET test framework? If so, which instructions worked for you?


Solution

  • When we run into problems troubleshooting our application with unit tests (some of the libraries we use do not like running in a unit test environment) we simply create a console application that calls the test methods in the same order as the unit testing framework does. You then start the profiler on the console app.

    You may not need to run all the tests to find out what the leak is.

    We also encountered leaks in unmanaged memory that are not always visible from managed memory tracking tools. You need to specifically look for the unamanaged memory. These often result from missing Dispose() calls.