How to keep a reference for C structure to avoid GC?

Don’t use a global dict, that’s not generic and is the slowest possible solution.

What you can use depends on how you are calling the C code. A possible solution that should work in most cases is https://github.com/JuliaPy/PyCall.jl/blob/314ac274326e78f12fbcb73ae0f17f63a3f4bba9/src/pytype.jl#L314