# Destructor for structs

**URL:** <https://discourse.julialang.org/t/destructor-for-structs/39748>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 19, 2020, 12:21pm UTC](https://discourse.julialang.org/t/destructor-for-structs/39748 "2020-05-19T12:21:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [May 19, 2020, 12:21pm UTC](https://discourse.julialang.org/t/destructor-for-structs/39748/1 "2020-05-19T12:21:36Z")

</div>

Does Julia lang has something like a _destructor_ or _finalizer_ for structs?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [May 19, 2020, 12:43pm UTC](https://discourse.julialang.org/t/destructor-for-structs/39748/2 "2020-05-19T12:43:06Z")

</div>

There are finalizers:

```julia
help?> finalizer
search: finalizer UndefInitializer finalize

  finalizer(f, x)

  Register a function f(x) to be called when there are no program-accessible references to x, and return x. The type of x must be a mutable struct, otherwise the
  behavior of this function is unpredictable.

  f must not cause a task switch, which excludes most I/O operations such as println. @schedule println("message") or ccall(:jl_, Cvoid, (Any,), "message") may be
  helpful for debugging purposes.

```

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [May 31, 2020, 1:32pm UTC](https://discourse.julialang.org/t/destructor-for-structs/39748/3 "2020-05-31T13:32:44Z")

</div>

Note that the help message is not correct and has been replaced in the [master documentation](https://docs.julialang.org/en/v1.6-dev/base/base/#Base.finalizer).
