MATLAB: Matlab doesn’t release memory when variables are cleared

memory problems.

I am working with very large data sets (~50 GB) in matlab R2015a. When I clear variables, matlab frequently does not release the memory. I have tried clear all, clear classes, clear java and running the java garbage collector. The only way I can get matlab to release the memory is close and restart matlab. Is there a better way?

Best Answer

It has more to do with Windows and how its memory-management routines work (or not) regarding what memory that is marked as unused by the application is actually physically released and when. Also, even though there may be sufficient total free memory, it is free contiguous memory that is limiting when creating arrays; if there isn't sufficient for the job, you're stuck.
There are guidelines to help and also some newer techniques more recently introduced you can try--
Related Question