Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Is Clearing Redundant Cells Necessary

1 回表示 (過去 30 日間)
Jay
Jay 2016 年 10 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
If I am running a Main script then executing sub-scripts, is there any point in me clearing the redundant cells no longer needed or does executing the sub-routine delete all other non global cells?

回答 (2 件)

Stephen23
Stephen23 2016 年 10 月 3 日
編集済み: Stephen23 2016 年 10 月 3 日
Scripts use the caller's workspace, and do not "clear" anything from memory unless this is explicitly written in the script. The best answer to your question is going to be: "stop using scripts for serious code, and learn to use functions". Then these kinds of beginner questions become irrelevant (as the MATLAB memory manager intelligently takes care of tidying up variables inside function workspaces).

Adam
Adam 2016 年 10 月 3 日
What do you mean by a sub-script? Scripts use the base workspace so if you call one script from another (which I assume is what you mean) everything from both scripts will remain in the base workspace, so if your cell array takes up a lot of memory then it will continue to do so. Whether it is worth clearing or not depends if that memory is excessive. If not then don't bother as it will take up time in the running of the script (if speed is an issue for you)
  2 件のコメント
Adam
Adam 2016 年 10 月 3 日
編集済み: Adam 2016 年 10 月 3 日
To correct that, as Stephen Cobeldick more accurately describes, the workspace is that of the function that called the script. I just only ever run scripts from the command line for quick temporary stuff so I forgot that!
Stephen23
Stephen23 2016 年 10 月 3 日
編集済み: Stephen23 2016 年 10 月 3 日
"Scripts use the base workspace" is wrong. Scripts actually use the workspace of where they are called from, as the documentation clearly states:
"When you call a script from a function, the script uses the function workspace."
This is an important distinction, which significantly affects the topic of memory management (and therefore this question), as function workspaces are cleared intelligently by MATLAB's cleanup process. The OP did not tell us how or from what workspace these scripts are being called.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by