Precompilation and finalizers

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:

module MyMod

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

const precompiled_s = S()

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?