# What happens to overwritten Modules?

**URL:** https://discourse.julialang.org/t/what-happens-to-overwritten-modules/89711
**Category:** General Usage
**Created:** [November 3, 2022, 11:21am UTC](https://discourse.julialang.org/t/what-happens-to-overwritten-modules/89711 "2022-11-03T11:21:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [November 3, 2022, 11:21am UTC](https://discourse.julialang.org/t/what-happens-to-overwritten-modules/89711/1 "2022-11-03T11:21:10Z")

</div>

Some packages create a new sandbox module for each run of let’s say a document generator, or a code cell in a documenter project. Do these modules take up more and more space because they’re never removed? Or what are the requirements for removing them?

Here’s one short example that shows that even though a module is “overwritten” it is still accessible if previously assigned to another variable. If that variable `x` didn’t exist in my example, would the whole overwritten module get garbage collected, all its functions removed from the global method table, etc? Or does a module always hang around in memory once created, just not accessible anymore by normal means?

```julia
julia> module A
           function f()
               println("hi")
           end
       end
Main.A

julia> x = Main.A
Main.A

julia> x.f()
hi

julia> module A
           function f()
               println("hey")
           end
       end
WARNING: replacing module A.
Main.A

julia> x.f()
hi

julia> A.f()
hey

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [November 3, 2022, 12:23pm UTC](https://discourse.julialang.org/t/what-happens-to-overwritten-modules/89711/2 "2022-11-03T12:23:01Z")

</div>

modules stick around forever.
