|On this page…|
To clear a memmapfile object from memory, do any of the following:
Reassign another value to the memmapfile object's variable
Clear the memmapfile object's variable from memory
Exit the function scope in which the memmapfile 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 because no memory actually gets copied. In the following statement, d is a shared data copy of the data mapped from the file:
d = m.Data;
When you finish using the mapped data, make sure to clear any variables that share data with the mapped file before clearing the memmapfile 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 cleared. If access to the mapped file was over a network, then copying this data to local memory can take considerable time. Therefore, if you assign m.Data to the variable, d, you should be sure to clear d before clearing m when you are finished with the memory map.