I use JuMP.jl with HiGHS.jl to solve an optimisation problem, then generate a shared library for this using JuliaC.jl. The shared library is used within a larger software. It is loaded once (at startup), and then always the same Base.@ccallable function is called, which executes the optimisation.
It does the usual stuff, i.e.
model = Model(HiGHS.Optimizer)
# add variables, constraints, and an objective
optimize!(model)
# get values of some variables, termination status, etc.
# return extracted information
Now, we’re dealing with segfault issues.
It came to my mind that HiGHS itself again loads (via HiGHS_jll.jl) a library. Then, probably when creating the julia-level model, it creates a HiGHS instance via Highs_create. The usual C-API workflow would then be to call Highs_destroy once everything is done. Otherwise, one would just leak memory by keeping all those old HiGHS instances around, right?
How is this handled throughout the chain from JuMP.jl through MathOptInterface.jl and HiGHS.jl, down to HiGHS_jll.jl? Is there a high-level interface to free allocated memory (by destroying the HiGHS instance) before I return from the function in the shared library I create?
Thanks for any help in advance!