In Matlab 2014b
, when I use CLEAR ALL
at the beginning of the script I get the following warning,
For improved performance, consider not using CLEAR ALL within a script
which is not given in the previous releases (As I recall).
The only reason I found is that, when you call a script from outside or from other scripts you do not want to clear the variables in the workspace, and re-generate them every time again and again.
Is there any other reason that I am missing?
How does removing CLEAR ALL
improves the performance when using a single script?
Actually, clearing cache and cookies can significantly improve the speed and performance of your browser.
Delete temporary files. Temporary files like internet history, cookies, and caches take up a ton of space on your hard disk. Deleting them frees up valuable space on your hard disk and speeds up your computer.
In R2015b, the semantics of clear
were changed. Perhaps in response to the concerns raised in this question, the changes stated in the release notes are:
The
clear
function no longer clears debugging breakpoints. To clear breakpoints, usedbclear all
.The
clear
function only clears functions that are not currently running. For example, when you callclear myFun
whilemyFun
is running,myFun
is not cleared.
This part pertains to pre-R2015b MATLAB versions.
Here's a table of what gets cleared with each input argument.
The table for R2015b is identical except that there is no longer a "Debugging breakpoints" column since they are no longer cleared with clear
.
Scripts and functions are cleared, when you can probably just clear variables
(red boxes). It does not make a lot of sense to clear the function from memory that is presently being executed. (According to R2015b release notes, this does not happen.)
Also, keeping in mind that scripts execute in the base workspace, you are clearing out all functions that may be used by other scripts. Try looking at the output of inmem
after an extended MATLAB tinkering session. You fill find all kinds of MATLAB functions that are loaded into memory for fast access (including 'matlabrc'
, 'pathdef'
, and other core scripts that setup your workspace). So, perhaps it's not that it hurts performance of just the script where you call clear all
but all other scripts and the interactive command line that is in the base workspace. That would be my guess.
Not performance related, but another reason why a clear all
in a script might be a bad idea is that it will clear breakpoints (this can be annoying!), and global+persistent variables. However, it might be the goal to clear global and peristent variables. For global there's clear global
, but there's nothing like that for persistent since persistent variables are bound to functions and you would use clear functions
or clear whateverFunctionName
for them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With