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

Finalizers for modules? #8764

Closed
jakebolewski opened this issue Oct 22, 2014 · 6 comments
Closed

Finalizers for modules? #8764

jakebolewski opened this issue Oct 22, 2014 · 6 comments

Comments

@jakebolewski
Copy link
Member

I have had a couple of instances where this feature would be nice to have in terms of dealing with global state when interfacing with some external c-library. Thinking through some of the implications of #8745, it seems like it would be necessary to support pre-compiling packages in many instances (at least for some I have written).

@JeffBezanson
Copy link
Member

When would this be called? At exit?

@jakebolewski
Copy link
Member Author

At exit would be for the use cases I was thinking about. I don't know how module reloading would play into this.

@JeffBezanson
Copy link
Member

Calling atexit in __init__ would probably work for that.

@jakebolewski
Copy link
Member Author

calling atexit does not guarantee finalization order, so you can still have live objects with handles pointing to resources allocated within the library you are trying to close.

@vtjnash
Copy link
Member

vtjnash commented Oct 23, 2014

all atexit handlers are called before all finalizers which remain active at program exit. what is your desired order?

@jakebolewski
Copy link
Member Author

It is a common pattern where objects retaining handles to allocated resources often free their resources when the object is gc'd. I guess the behavior I'm looking for is for the "module finalizer" to run after all other active finalizers have been run. This usually would be some ccall to the c library's teardown handler.

maleadt added a commit to JuliaLLVM/LLVM.jl that referenced this issue Oct 17, 2016
Module finalizers (JuliaLang/julia#8764) would be a better option here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants