Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory cleaning #443

Closed
matheusdiogenesandrade opened this issue Feb 16, 2024 · 2 comments
Closed

Memory cleaning #443

matheusdiogenesandrade opened this issue Feb 16, 2024 · 2 comments

Comments

@matheusdiogenesandrade
Copy link

Hello.

I am trying to promote further analysis on the memory management, and, at the moment, I am looking for the snippets responsible for calling the end() function (cf. here and here for the C++ API reference) of the Cplex C API in the julia code. I would like to know if someone could point me such snippets.

Thanks and regards.

@odow
Copy link
Member

odow commented Feb 16, 2024

CPLEX.jl does not use the C+++ API, so it does not call end().

Objects are freed via a finalizer that runs when Julia's GC frees the associated CPLEX Model or Env

finalizer(env) do e
e.finalize_called = true
if e.attached_models == 0
# Only finalize the model if there are no models using it.
CPXcloseCPLEX(Ref(e.ptr))
e.ptr = C_NULL
end
end

finalizer(model) do m
ret = CPXfreeprob(m.env, Ref(m.lp))
_check_ret(m, ret)
m.env.attached_models -= 1
if env === nothing
# We created this env. Finalize it now
finalize(m.env)
elseif m.env.finalize_called && m.env.attached_models == 0
# We delayed finalizing `m.env` earlier because there were still
# models attached. Finalize it now.
CPXcloseCPLEX(Ref(m.env.ptr))
m.env.ptr = C_NULL
end
end

I assume this questions is related to https://discourse.julialang.org/t/memory-management-in-cplex-jl/109704. I don't have any suggestions other than what I mentioned there.

@matheusdiogenesandrade
Copy link
Author

Thank you very much, that is exactly what I am looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants