Memory Fragmentation
Memory fragmentation happens when a large portion of a computer's random access memory (RAM) is separated into many non-contiguous chunks. The fragmentation can leave a high percentage of RAM memory unused but also unusable resulting in memory issues. If RAM is low or unusable, an application will use the computer's hard drive as virtual memory (which slows operations) or report low or out of memory problems.
Memory fragmentation is common with data intensive applications such as ExtendSim, where the allocation, disposal, and reallocation of memory is ongoing during model runs. For example:
There are two ways to deal with reports of memory issues:
Memory Leaks
Memory leaks occur if some of the memory used in an operation doesn't get properly disposed of at the end of that operation. For example, this happens if a custom block's dynamic array is not properly disposed of in the code. A small memory leak won't cause a problem but memory leaks become significant if they accumulate. This could happen, for example, if the memory for that dynamic array is constantly being reallocated, but not disposed of, over multiple runs. While memory leaks can also occur from ExtendSim, most memory leaks are caused by the code in custom blocks.
There are two ways to deal with reports of memory leaks:
Memory Usage
You might notice that the second and subsequent runs of a simulation take longer to run and use more memory than the first run. Most often that is because a large amount of data has been stored in the model during the first run. In subsequent runs, that data has to be disposed of before it can be replaced with new data, causing longer processing times.
The RealTimer block, discussed above, is helpful for determining how much memory and simulation time specific blocks are using during runs.
For more information about memory management in ExtendSim, please see Quick Tips • Memory Management in the ExtendSim Learning Center.