# Delete a module

**URL:** <https://discourse.julialang.org/t/delete-a-module/62226>\
**Category:** General Usage\
**Created:** [June 1, 2021, 8:30pm UTC](https://discourse.julialang.org/t/delete-a-module/62226 "2021-06-01T20:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [June 1, 2021, 8:30pm UTC](https://discourse.julialang.org/t/delete-a-module/62226/1 "2021-06-01T20:30:55Z")

</div>

Is it possible to delete a module so it can be GCed?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [June 1, 2021, 8:42pm UTC](https://discourse.julialang.org/t/delete-a-module/62226/2 "2021-06-01T20:42:47Z")

</div>

As far as I know, no you cannot. However, you could go into a module and set all it’s non-constant bindings to `nothing` which will at least allow those bindings to be GC’d

```julia
julia> module Foo
       a = [1,2,3]
       b = "hi"
       f(x, y) = x + 1
       const c = 1
       d = 100
       end
Main.Foo

julia> getproperty.((Foo,), names(Foo, all=true))
11-element Vector{Any}:
    typeof(Main.Foo.eval)
    typeof(Main.Foo.f)
    typeof(Main.Foo.include)
    Main.Foo
    [1, 2, 3]
    "hi"
   1
 100
    eval (generic function with 1 method)
    f (generic function with 1 method)
    include (generic function with 2 methods)

julia> function clear!(M::Module)
           for name ∈ names(M, all=true)
               if !isconst(M, name)
                   @eval M $name = $nothing
               end
           end
       end
clear! (generic function with 1 method)

julia> clear!(Foo)

julia> getproperty.((Foo,), names(Foo, all=true))
11-element Vector{Any}:
  typeof(Main.Foo.eval)
  typeof(Main.Foo.f)
  typeof(Main.Foo.include)
  Main.Foo
  nothing
  nothing
 1
  nothing
  eval (generic function with 1 method)
  f (generic function with 1 method)
  include (generic function with 2 methods)

```

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [June 1, 2021, 8:47pm UTC](https://discourse.julialang.org/t/delete-a-module/62226/3 "2021-06-01T20:47:50Z")

</div>

Maybe one further enhancement would be to have a branch like

```julia
if isconst(M, name) && applicable(empty!, getproperty(M, name))
    empty!(getproperty(M, name))
end

```

this way, if you have something like a global constant dictionary or array, it’ll get emptied.
