# Explain the UniquedById example in the manual

**URL:** https://discourse.julialang.org/t/explain-the-uniquedbyid-example-in-the-manual/135413
**Category:** New to Julia
**Created:** [February 2, 2026, 8:53pm UTC](https://discourse.julialang.org/t/explain-the-uniquedbyid-example-in-the-manual/135413 "2026-02-02T20:53:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![paiv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paiv/32/218059_2.png) [@paiv](https://discourse.julialang.org/u/paiv)
#### Post date: [February 2, 2026, 8:53pm UTC](https://discourse.julialang.org/t/explain-the-uniquedbyid-example-in-the-manual/135413/1 "2026-02-02T20:53:24Z")

</div>

The manual section [Module initialization and precompilation](https://docs.julialang.org/en/v1/manual/modules/#Module-initialization-and-precompilation) gives this example of a bad pattern:

```julia
mutable struct UniquedById
    myid::Int
    let counter = 0
        UniquedById() = new(counter += 1)
    end
end

```

> All subsequent usages of this incrementally compiled module will start from that same counter value.

I am trying to recreate the full scenario where this code becomes an issue. I can put this code in a package and use it in a script, the package will be precompiled and cached. What would be my next steps that will reveal the issue?

---

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [February 3, 2026, 5:38am UTC](https://discourse.julialang.org/t/explain-the-uniquedbyid-example-in-the-manual/135413/2 "2026-02-03T05:38:28Z")

</div>

After you put this code in a package `UniquedByIds`, you can create another package `A`. `A` can use `UniquedByIds` to e.g. create a global object of `UniquedById`.

When you now use both packages from the REPL and create another object of `UniquedById` in `Main` and compare this object with the global object in `A`, you’ll see the problem.

---

<div class="post-metadata">

### Author: ![paiv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paiv/32/218059_2.png) [@paiv](https://discourse.julialang.org/u/paiv)
#### Post date: [February 3, 2026, 8:06am UTC](https://discourse.julialang.org/t/explain-the-uniquedbyid-example-in-the-manual/135413/3 "2026-02-03T08:06:34Z")

</div>

Thank you, that works.
