In a MEX-file, your use of mxFree depends on whether the specified memory parcel is persistent or nonpersistent. By default, memory parcels created by mxCalloc, mxMalloc, and mxRealloc are nonpersistent. The memory management facility automatically frees all nonpersistent memory whenever a MEX-file completes. Thus, even if you do not call mxFree, MATLAB takes care of freeing the memory for you. Nevertheless, it is good programming practice to deallocate memory as soon as you are through using it. Doing so generally makes the entire system run more efficiently.
Partager