MATLAB: Is the memory of a Simulink.ModelDataLogs variable not freed when I clear a reference to it using a ‘Clear All’ command in the MATLAB workspace

leakmemstatsmodeldatalogsobjectsimulink

I have a reference to a Simulink.ModelDataLogs container in the MATLAB workspace. When I use a 'Clear All' command in the MATLAB command window, this reference is cleared. However, the memory of the container itself is not freed. The memory is freed only when I close the model.

Best Answer

This enhancement has been incorporated in Release 2011a (R2011a). For previous product releases, read below for any possible workarounds:
The fact that the container memory is not freed is not a bug in Simulink. All references to ModelDataLogs in the workspace are just that: references. To save memory, no copy of the data is made, and the model retains the master copy. Another reason to not free the ModelDataLogs memory, and thereby clear the data it contains, is to support the TimeSeries GUI, which may be holding on to a reference to the ModelDataLogs.
The ModelDataLogs memory is cleared when the model is closed or a new simulation is begun. As a workaround, simulate the model for 0 seconds. This will free the memory associated with the model.