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

Missing GC.@preserves? #100

Closed
tkoolen opened this issue Jan 31, 2019 · 9 comments
Closed

Missing GC.@preserves? #100

tkoolen opened this issue Jan 31, 2019 · 9 comments

Comments

@tkoolen
Copy link
Contributor

tkoolen commented Jan 31, 2019

Cbc.jl doesn't have a single GC.@preserve statement, but post-0.6, I really think it should. What's preventing prob from being garbage collected in calls like

https://github.com/JuliaOpt/Cbc.jl/blob/220f0fa5d94a4382261e76fc473ec494dd85382a/src/CbcCInterface.jl#L270

?

@mlubin
Copy link
Member

mlubin commented Jan 31, 2019

Last time I looked into this, I understood that function arguments are safe from GC collection because they can't be freed in the calling scope until after the function returns. Has this changed?

tkoolen added a commit to tkoolen/Cbc.jl that referenced this issue Jan 31, 2019
@tkoolen
Copy link
Contributor Author

tkoolen commented Jan 31, 2019

Even if that's the case (I personally haven't read that anywhere) prob.p (i.e., getproperty(prob, :p)) is the argument, prob itself isn't a ccall argument and may not be used anywhere else, so its finalizer,

https://github.com/JuliaOpt/Cbc.jl/blob/master/src/CbcCInterface.jl#L77

may be called.

@tkoolen
Copy link
Contributor Author

tkoolen commented Jan 31, 2019

Sorry, I didn't fully parse your message.

they can't be freed in the calling scope until after the function returns

This is definitely not true anymore in >0.6.

@tkoolen
Copy link
Contributor Author

tkoolen commented Jan 31, 2019

@tkoolen
Copy link
Contributor Author

tkoolen commented Jan 31, 2019

Maybe you read https://discourse.julialang.org/t/julia-v0-6-vs-v0-7-gc-behaviour/10002/6, but if that's still accurate, it's precedented on @noinline.

Edit: and see also https://discourse.julialang.org/t/julia-v0-6-vs-v0-7-gc-behaviour/10002/8.

@mlubin
Copy link
Member

mlubin commented Jan 31, 2019

Ok, I understand why function arguments wouldn't be special if the function is inlined. Thanks for the links.

@rschwarz
Copy link

I have not read all the links completely, but are you worried that prob will be GC'ed during, after, or even because of the call to solve, even though prob is still referenced in some outer scope?

@tkoolen
Copy link
Contributor Author

tkoolen commented Jan 31, 2019

A problem is that prob::CbcModel might actually not be referenced anymore in some outer scope after one of the Cbc function calls, at least not in any GC-visible way, which as of right now allows Julia to potentially run the CbcModel finalizer before the ccall, and the ccalls expect prob.p to be a valid pointer.

@rschwarz
Copy link

Thanks for the clarification. I still can not imagine a scenario where this reference to prob is missing or "invisible", but I will read through the links in detail now.

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

3 participants