|On this page…|
It is not necessary to explicitly call a destructor method to clear a memmapfile object from memory when you no longer need it. MATLAB® calls the destructor for you whenever you do any of the following:
Reassign another value to the memmapfile object's variable
Clear the object's variable from memory
Exit the function scope in which the object was created
When you assign the Data field of the memmapfile object to a variable, MATLAB makes a shared data copy of the mapped data. This is very efficient as no memory actually gets copied. In the following statement, memdat is a shared data copy of the data mapped from the file:
memdat = m.Data;
When you finish using the mapped data, make sure to clear any variables that shared data with the mapped file before clearing the object itself. If you clear the object first, then the sharing of data between the file and dependent variables is broken, and the data assigned to such variables must be copied into memory before the object is destroyed. If access to the mapped file was over a network, then copying this data to local memory can take considerable time. So, if the statement shown above assigns data to the variable memdat, you should be sure to clear memdat before clearing m when you are finished with the object.