What happens to overwritten Modules?

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> 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

modules stick around forever.