# Non-Deterministic Memory Allocation?

**URL:** https://discourse.julialang.org/t/non-deterministic-memory-allocation/104941
**Category:** General Usage
**Tags:** question
**Created:** [October 13, 2023, 11:05pm UTC](https://discourse.julialang.org/t/non-deterministic-memory-allocation/104941 "2023-10-13T23:05:25Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [October 15, 2023, 2:30am UTC](https://discourse.julialang.org/t/non-deterministic-memory-allocation/104941/6 "2023-10-15T02:30:41Z")

</div>

> [@mcmuffin6o](#):
>
> As a side note, if I tried to recommend Julia in its current state to a bunch of MATLAB junkies, I’d get laughed out of the room as soon as they ask about whether or not it’s possible to do something as trivial as _clearing the workspace_.

MATLAB’s [`clear`](https://www.mathworks.com/help/matlab/ref/clear.html?searchHighlight=clear&s_tid=srchtitle_support_results_1_clear)/[`clearvars`](https://www.mathworks.com/help/matlab/ref/clearvars.html#bt3lb2_-2_1) is made feasible by MATLAB’s atypical [workspace system](https://www.mathworks.com/help/matlab/apiref/matlab.engine.workspacetype.html#) of storing variables. This links to a [somewhat old answer](https://www.mathworks.com/matlabcentral/answers/99602-how-can-i-use-global-variables-and-matlab-workspaces#answer_108950), but it’s a more detailed description of workspaces and their unique caveats.

This just doesn’t translate to languages with modules holding their own global variables, so this feature will never be fully replicated, if at all. Let’s take a simple case where you fire up the REPL and work in `Main`. After polluting the namespace with a bunch of variables and data, you decide to remove them. First problem: you want to keep the already compiled functions; okay, we’ll keep any variable assigned to an instance of `Function`. Second problem, you don’t want to remove `const` variables because they were inlined into your compiled functions and can’t be safely reassigned anymore; fine, let’s keep them too. Third problem, the functions relying on non-`const` global variables now don’t work, and you have to manually redefine them from memory. And now you realize that MATLAB risks easier naming conflicts by throwing global variables into their own workspace so that `clear ...` doesn’t easily cause such issues (though `clear global ...` and `clear all` do remove things from the global workspace and is _discouraged_ even in `clear`’s documentation).

In most languages, the repeatable unit of code is a function, and that should be used instead of tweaking and rerunning scripts. This practice is recommended in [MATLAB](https://www.mathworks.com/help/matlab/matlab_prog/techniques-for-improving-performance.html) as [well](https://www.mathworks.com/matlabcentral/answers/272064-difference-between-clear-and-clear-all#comment_348654) by the real junkies.

---

_[View the full topic](https://discourse.julialang.org/t/non-deterministic-memory-allocation/104941)._
