# Precompilation and finalizers

**URL:** <https://discourse.julialang.org/t/precompilation-and-finalizers/90635>\
**Category:** General Usage\
**Tags:** precompilation\
**Created:** [November 22, 2022, 10:00am UTC](https://discourse.julialang.org/t/precompilation-and-finalizers/90635 "2022-11-22T10:00:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [November 22, 2022, 10:00am UTC](https://discourse.julialang.org/t/precompilation-and-finalizers/90635/1 "2022-11-22T10:00:51Z")

</div>

I wanted to register a finalizer for instances of some specific type. The final requirement is to achieve the following features simultaneously:

1. invoking some callback once the object is gc-ed
2. keeping the object precompile-able

Unfortunately, it seems that my finalizer got lost after precompilation:

```julia
module MyMod

mutable struct S
    function S()
        self = new()
        finalizer(self) do x
            println("call finalizer")
        end
        self
    end
end

const precompiled_s = S()
end

```

If I precompile the module `S`, and load the module again, the finalizer never gets called.

How could I restore my finalizers registered to the all objects of `S`?
