Yes, if the Memory Being Used is shown as higher than your RAM, your system must be allocating virtual memory, probably from a hard disk. That can be very slow, and it usually gets slower as more memory is swapped to hard disk.
When a lot of memory is being swapped to hard disk, the system on the whole can get quite slow. When you press control-C, because there is no way to throw/catch a control-C, any functions in the calling stack and all non-persistent memory in the workspace (there there is no other reference to) must be released, which probably involves bringing that variable back into active memory again (forcing swaps.)
If you see that memory used by MATLAB has increased even when you are at the command line (no routines on the call stack), there are some possible reasons:
- internal buffers may have been allocated, such as for Data Acquisition
- memory might have become fragmented enough that MATLAB cannot figure out that there are adjacent chunks that could be put together again
- You might have used global variables, as those are not freed when the functions terminate
- You might have created a bunch of graphics objects that have not been cleared out yet. If you used "hold on" and did not notice that you were covering over old objects, then the memory allocated for graphics can grow large
- You might have Objects associated with callback routines associated with objects that have not been cleared (such as timers)
- If I recall correctly, MATLAB uses (or used to) a dual memory allocation strategy, in which memory requests under a particular size are handled out of fix-length chunks of memory, and memory requests over that size are handled by allocating as much memory as is needed to fit. When one of the large chunks is no longer used, MATLAB logically gives it back to the operating system (on MS Windows), but when one of the fixed-sized blocks is no longer used, MATLAB holds on to it, under the assumption that you are probably going to need another variable the same size in another few microseconds. Because of this strategy, if you use a lot of small values, the amount of memory that MATLAB is holding on to for later use can continue to grow
Best Answer