# Removing objects on memory, again. Alternatives to A = nothing?

**URL:** <https://discourse.julialang.org/t/removing-objects-on-memory-again-alternatives-to-a-nothing/19744>\
**Category:** General Usage\
**Created:** [January 17, 2019, 12:47pm UTC](https://discourse.julialang.org/t/removing-objects-on-memory-again-alternatives-to-a-nothing/19744 "2019-01-17T12:47:44Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 17, 2019, 1:47pm UTC](https://discourse.julialang.org/t/removing-objects-on-memory-again-alternatives-to-a-nothing/19744/5 "2019-01-17T13:47:40Z")

</div>

> [@Juan](#):
>
> Anyway, why do you, Julia developers, think having an rm() command can hurt or be bad in any way?

Because we’re mean, nasty people 😈

Nah, just kidding. It’s because being able to undefine things that have already been defined is pretty fundamentally incompatible with many assumptions that the Julia compiler makes when generating code. Those assumptions could potentially be relaxed but it would entail a lot of annoying work for a feature that isn’t strictly necessary and doesn’t really help you _do_ anything.

It might be possible these days to implement this feature by creating a new `Main` module and copying all the bindings from the old `Main` into the new one except for the ones that you want to clear and then throwing out the old `Main`. However, there are a some major caveats to that approach:

1. This won’t free any memory since there will still be references to the old `Main` module.
2. It also won’t handle functions that refer to old globals correctly since the functions will still use the old versions of these globals in the old `Main` module.

So the better way to do this feature may be to just allow non-const globals to be put back into the undef state that globals can be in before they are first defined. That’s a significant compiler project, however, and pretty hard to motivate. Where would you rank it on the list of [compiler work priorities](https://discourse.julialang.org/t/compiler-work-priorities/17623)? I find it hard to put it anywhere but the very bottom (even if we added quite a few other projects I can think of to the list). Of course, maybe it would be a good first project for someone looking to get into compiler work.

---

_[View the full topic](https://discourse.julialang.org/t/removing-objects-on-memory-again-alternatives-to-a-nothing/19744)._
