Main Content

Clean Up MATLAB Resources

Clean Up Client Configuration

You can clean up the client configuration any time after it is used to create the client context. The context copies the required configuration values when it is created.

To clean up the client configuration, use the mpsClientRuntime destroyConfig() function with a pointer to the client configuration data.

mpsClientRuntime* mpsruntime = mpsInitialize();
mpsClientConfig* config;
mpsStatus status = mpsruntime->createConfig(&config);
mpsClientContext* context;
status = mpsruntime->createContext(&context, config);
...
mpsruntime->destroyConfig(config);

Clean Up Client Context

The client context encapsulates the connection framework between the client and a server instance. It is required to evaluate MATLAB® functions. The context also performs a number of tasks to optimize the connections to server instances.

The client context should not be cleaned up until the client is done evaluating MATLAB functions.

Clean up the client context using the mpsClientRuntime destroyContext() function with a pointer to the client context data.

mpsClientRuntime* mpsruntime = mpsInitialize();
mpsClientConfig* config;
mpsStatus status = mpsruntime->createConfig(&config);
mpsClientContext* context;
status = mpsruntime->createContext(&context, config);
...
mpsruntime->destroyContext(context);

Clean Up Client Runtime

When you are finished using the client API, clean up the runtime resources using the mpsTerminate() function.

Note

mpsTerminate() does not clean up the client context or the client configuration. They must be cleaned up before calling mpsTerminate().

Clean Up MATLAB Arrays

MATLAB arrays stored in mpsArray variables are opaque. They contain a number of fields used to marshal data between your C client code and the MATLAB Runtime. Variables containing MATLAB arrays can be large.

Clean up variables containing MATLAB arrays using the mpsDestroyArray() function. The mpsDestroyArray() function takes a pointer to the MATLAB array being cleaned up. It frees all of the memory used by the array.

Note

When cleaning up the arrays used as inputs and outputs of an feval() call, you must clean up all of the MATLAB arrays contained in the array before you destroy the MATLAB array pointing to the inputs or outputs.

Clean up the data used in an feval() call.

const mpsArray** const inVal = new const mpsArray* [numIn];
...
mpsArray **outVal = new mpsArray* [numOut];
...
status = mpsruntime->feval(context,funUrl, numOut, outVal,
                           numIn, inVal);
if (status==MPS_OK)
{
  ...
  for (int i=0; i<numOut; i++)
    mpsDestroyArray(outVal[i]);
  delete[] outVal;
}
for (int i=0; i<numIn; i++)
  mpsDestroyArray(inVal[i]);
delete[] inVal;