Clear Filters
Clear Filters

Where is the workspace saved?

24 views (last 30 days)
Patrick Aoun
Patrick Aoun on 16 Sep 2016
Edited: Stephen23 on 16 Sep 2016
Pretty straightforward question I guess. Where is the workspace held, in my computer? Is it on the RAM, on the hard drive, or a combination of both?
Is any form of "workspace management" useful? Such as clearing unused variables, or avoiding to keep a lot of huge variables loaded at the same time?

Accepted Answer

Image Analyst
Image Analyst on 16 Sep 2016
The workspace is saved in RAM memory. You can also save it to disk to a mat file if you call save(). The main functions for cleaning up are clc, clear, close, and delete. Each of those has several options so check them out in the help. One way to clean up most stuff is
clc;
close all force;
clear all;
clear global;
You can make a shortcut on your toolbar called "Clean up" to do all that. It's often recommended to make such a button by Mathworks trainers.
  2 Comments
Patrick Aoun
Patrick Aoun on 16 Sep 2016
Thanks! That definitely explains why my parfor loop is obliterating my RAM...
Stephen23
Stephen23 on 16 Sep 2016
Edited: Stephen23 on 16 Sep 2016
"Is any form of "workspace management" useful?"
MATLAB intelligently looks after memory, allocating and freeing it up as needed. Good programming practices (such as writing functions rather than scripts, and keeping data together as much as possible) make explicitly clearing data unnecessary. In a few edge-cases this memory management might do something unexpected, but generally you should just leave it up to MATLAB.
If you have some very large arrays and need to clear them otherwise you will run out of memory, then by all means do so. Just keep in mind what the clear documentation says: "Calling clear all, clear classes, and clear functions decreases code performance, and is usually unnecessary." You might like to read about clearvars, which is more useful than clear for clearing variables.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!