Main Content

<library>Terminate

Free all resources allocated by MATLAB Runtime instance associated with library

Description

example

libraryTerminate() frees all resources allocated by the MATLAB® Runtime instance associated with the generated C/C++ shared library library. Call this function in your C/C++ application after you finish calling the functions in this generated library and before calling mclTerminateApplication.

Examples

collapse all

Terminate a C shared library named libmatrix.

  1. Call the initialization function for the C library libmatrix in the main function of your C application code.

        ...
    /* Call the library initialization routine and ensure the
    *  library was initialized properly. */
    if (!libmatrixInitialize())
    {
        fprintf(stderr, 
                "An error occurred while initializing: \n %s ",
                mclGetLastErrorMessage());
        return -2;
    }
    else
    {
    /* Call the library function(s) for your application */
        ...
    
  2. At the end of the else statement (before calling mclTerminateApplication), call libmatrixTerminate to free resources allocated by the MATLAB Runtime instance associated with libmatrix.

        ...
    /* Call the library termination routine */
    libmatrixTerminate();
    /* Free the memory created */
    mxDestroyArray(in1); in1=0;
    mxDestroyArray(in2); in2 = 0;
    }
  3. Finally, call mclTerminateApplication to terminate the MATLAB Runtime instance associated with libmatrix.

    /* mclTerminateApplication shuts down MATLAB Runtime. 
         * You cannot restart it by calling mclInitializeApplication.
         * Call mclTerminateApplication once and only once in your application.
         */
        mclTerminateApplication();
        return 0;
    }

Input Arguments

collapse all

Library name, specified as part of the function name. The library must be a C/C++ shared library generated by MATLAB Compiler SDK™.

Example: libmatrix

Version History

Introduced in R2015a