Stop MATLAB when not enough memory

6 views (last 30 days)
Chung Truong Thanh
Chung Truong Thanh on 29 Sep 2016
I use Window 10 64 bit, 24 GB RAM, MATLAB R2016a. In occasion when I run data with big size, memory is full 100%. The computer is hang and it is unable to close MATLAB or do anything else but restart.
My question is how to avoid this issue. For example if there is an pop-up to quit program when memory is full 100%, or some warning of full memory. It will allow me to reduce data size before running, or clear unused data... instead of restart the hung computer as I must do right now.
Thank you.
  1 Comment
KSSV
KSSV on 29 Sep 2016
There is an option to check memory in matlab. Doc memory. You can check how much memory is left and put some limit on your own, and using if statement you can either exit matlab or break/ stop the code. But, I don't think this is the solution for the problem.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 29 Sep 2016
One thing that can help is to use Preferences -> Workspace and enable "Limit the maximum array size to a percentage of RAM" and choose a size there.
When you have that in effect, it does not control the total memory to be used, but when you ask to create or assign into an array and that would make that particular array larger then the limit you set, then MATLAB would throw an error.
This will not deal with the issue of just accumulating enough variables in total that the memory fills up. For example if you limit to 75% but then build 7 variables each of which fills up 15% of memory, you would still run out of memory (7*15% = 105%).
  1 Comment
Chung Truong Thanh
Chung Truong Thanh on 29 Sep 2016
Thank you. It is true that this helps, but not quite solve my problem.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!