Main Content

clibRelease

Release C++ object from MATLAB

Description

example

clibRelease(cppObj) releases C++ object from MATLAB, making it inaccessible.

Examples

collapse all

This C++ class has functions to create and delete Myclass objects. Use the clibRelease function to manage memory for deleted objects.

Create a header file header.hpp with these statements.

class Myclass{};
Myclass* createMyclass() { return new Myclass(); }
void deleteMyclass(Myclass* myc) { delete myc; }

Build an interface to Myclass.

clibgen.buildInterface('header.hpp','TreatObjectPointerAsScalar',true);
addpath("header")

Create a Myclass object.

cppObj = clib.header.createMyclass
cppObj = 
  Myclass with no properties.

Call the deleteMyclass function. The Myclass object remains in the MATLAB® workspace.

clib.header.deleteMyclass(cppObj)
whos

Call clibRelease to release the memory.

clibRelease(cppObj);
cppObj
cppObj = 
  handle to deleted Myclass

Input Arguments

collapse all

C++ object created in MATLAB, specified as a handle. Once released, the underlying C++ object is no longer accessible in MATLAB, and the MATLAB handle cppObj becomes invalid. If the object is returned again from the library, then MATLAB creates a handle.

Introduced in R2019a