Can lingering testhost.exe processes be prevented after C# unit tests using a MATLAB .NET library?

I am experiencing an issue while running unit tests in a C# application that integrates a MATLAB module, which has been compiled as a .NET library using MATLAB Compiler SDK. During the testing process, the "testhost.exe" process is launched by design, as it is responsible for hosting the unit tests in C# environments such as MSTest or xUnit. Notably, "testhost.exe" only starts when the C# code calls the MATLAB .NET library, and does not launch if those calls are commented out.
The problem arises when "testhost.exe" remains visible in the Task Manager even after all the unit tests and the .NET library processes have completed. This lingering process suggests that resources may not be properly released, potentially leading to resource leaks or other issues during repeated testing or application deployment.

 Accepted Answer

The persistence of the "testhost.exe" process after test completion likely indicates that the MATLAB Runtime environment, which is required for executing MATLAB code from .NET, has not been fully shut down. To ensure a clean termination of the MATLAB Runtime and associated processes, it is necessary to explicitly invoke the termination function provided by the MATLAB Compiler SDK.
Specifically, after all MATLAB functions have been tested and no further MATLAB calls are planned, the function MWMCR.TerminateApplicationEx() should be called.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!