Why do I receive a memory allocation error when I try to run my Simulink model?

206 views (last 30 days)
I receive a memory allocation error when I try to run my Simulink model
Memory allocation error
What can I do to resolve the error?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Jan 2024
Edited: MathWorks Support Team on 16 Jan 2024
Memory allocation errors occur when MATLAB/Simulink requests more memory (RAM) from your operating system than is available. Given that MATLAB/Simulink use memory for a great variety of features, there are many different parts of a given model or script that may cause this issue. In order to isolate what might be taking up memory, be sure to consider:
  1. any other warnings or errors thrown along with the memory allocation error. These can be clues on where in your model/script to look. 
  2. the stage of the simulation where the error occurs. Update Diagram? Simulation? Code generation? Parallel simulation? This can also be an important clue. For example, if the error occurs during Update Diagram or code generation, then signal logging is unlikely to be the problem. 
Below are several common areas where Simulink consumes memory and some potential countermeasures for each: 
  1. Signal logging: By default, logged data in Simulink is logged to disk in the temp directory and only loaded into memory as needed. In other settings, data can be logged directly to memory . Examine your signal logging settings and size. Also notice if the memory issue occurs during simulation or when you try to access results after simulation. Consider the following tips to reduce the data logging memory requirements Limit the Size of Logged Data - MATLAB & Simulink (mathworks.com)
  2. Scopes and Visualizations: Data for scopes and dashboard blocks are stored in memory. Consider removing these blocks for long running simulations or reducing the amount of data displayed in them. 
  3. Diagnostics: Diagnostics such as warnings are stored in memory. If you see many thousands of warnings, consider addressing the root cause of the warning or disable the warning. 
  4. Workspace Variables: MATLAB variables in the Base Workspace and function workspaces take up memory. Use the whos() MATLAB function to check for large variables in your workspaces. List variables in workspace, with sizes and types - MATLAB whos (mathworks.com). Refer to the following troubleshooting guide for more advice: Resolve "Out of Memory" Errors - MATLAB & Simulink (mathworks.com).
  5. Size of states, parameters, and signals: Before running your model, Simulink must allocate memory to store all the signals, parameters, and states in your model. If you have a particularly large signal/parameter, such as a multidimensional or large matrix (in the millions of elements), see if reducing the size of this signal/parameter resolves the issue. 
  6. Parallel Workers: Parallel workers will by nature, increase your memory requirements. There must be enough available memory on the system to at least meet the minimum RAM requirement for each new  worker that is spawned. With Simulink, it is preferable to meet the recommended RAM requirement for each worker. System Requirements for MATLAB - MATLAB & Simulink (mathworks.com). Consider reducing your pool size to resolve memory issues. 
If you are still unable to solve your memory allocation error, consider reaching out the MathWorks Support, and mention what you have tried already. 

More Answers (0)

Categories

Find more on Configure and View Diagnostics in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!