Is there a way to prevent matlab from going into swap memory?

Sometimes when working with new code I inadvertently declare an array or too many arrays such that matlab starts working in swap memory. Sometimes I can get matlab to respond and clear the memory, but most of the time I have to explicitly kill the matlab processes and restart matlab. So what I'm wondering is if there is a way to tell matlab to throw an error if too much memory is requested; kind of like it did back when I was using 32-bit matlab and it would give "out-of-memory" errors.

 Accepted Answer

Which OS?
If you are using Linux or Mac OS-X, then you can use the shell "ulimit" command before you start up MATLAB in that shell. You would, in that case, probably want to use the "-v" option of ulimit.
If you are using MS Windows, then I am not familiar with the mechanisms for that, but you could ask Clippy.

6 Comments

That's great, I am using mac os-x most of the time and linux other times, but the setrlimit command seems to have the same functionality. Thanks for making me aware of this command.
Actually, I was a too hasty in accepting this answer, it appears that the -v option isn't supported under mac-os-x... is there are way to unaccept this answer?
setrlimit() is more directly the operating system call, and ulimit is the less formal and more user-friendly shell built-in intended to hide the OS limit-setting details. ulimit existed on unices before the major unix branches re-unified.
Back in my day....
ulimit works for me in OS-X ...
yokozuna:maple roberson$ echo $SHELL
/bin/bash
yokozuna:maple roberson$ ulimit -v 8888
yokozuna:maple roberson$ ulimit -v
8888
yokozuna:maple roberson$ uname -a
Darwin yokozuna.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh
yes it looks like it used to work, but from this thread it appears that it stopped working in leapard...
http://forums.macrumors.com/showthread.php?t=573616
Bleh.
This _might_ help: http://serverfault.com/questions/15564/where-are-the-default-ulimits-specified-on-os-x-10-5
http://stackoverflow.com/questions/3274385/how-to-limit-memory-of-a-os-x-program-ulimit-v-neither-m-are-working

Sign in to comment.

More Answers (1)

Also, keep in mind with 64-bit computing and memory getting less expensive all the time, it may actually be appropriate to set the swap for a system to something that would be considered "too small". The old "1.5 - 2 times RAM" guideline may no longer be appropriate.

Categories

Community Treasure Hunt

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

Start Hunting!