Why does the MCR crash when I re-run my compiled code?

I have a compiled application I created with MATLAB Compiler SDK and my main application calls the compiled M code multiple times. Each run is separate from each other. I am able to run the compiled code once from my main application and then the MCR crashes on the second go-around. I am starting up the MCR every time I call the compiled code and the shutting it down at the end.

 Accepted Answer

The MCR should be initialized once at the beginning of your main application (or the first time you call the compiled M code) and should not be torn down until the end of your main application. Stopping and restarting the MCR is undefined behavior, so since the MCR is being re-initialized while it is still active, it is crashing.
From the
:
"Shared MATLAB Runtime instance — When using MATLAB Compiler SDK, you can create a shared MATLAB Runtime instance, also known as a singleton. When you invoke MATLAB Compiler with the -S option through the compiler (using either mcc or a compiler app), a single MATLAB Runtime instance is created for each COM component or Java package in an application. You reuse this instance by sharing it among all subsequent class instances. Such sharing results in more efficient memory usage and eliminates the MATLAB Runtime startup cost in each subsequent class instantiation. All class instances share a single MATLAB workspace and share global variables in the deployed MATLAB files. MATLAB Compiler SDK creates singletons by default for .NET assemblies. MATLAB Compiler creates singletons by default for the COM components used by the Excel add-ins."

More Answers (0)

Categories

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!