-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Type Finalizers #1037
Comments
Yes, it really couldn't be a method call. We would get a bit of savings by not having to store finalizers per-object. But, this is pretty "featurey". |
How about always calling the |
No, that is way too slow. And we want to preserve the possiblity of doing GC that is O(1) in the number of dead objects. |
Can this issue be closed? |
I'm not sure we have a good solution yet. |
If we view the finalizer as a static part of the type (like inner constructors) should the method be defined in the type definition? mutable struct SomeType
#Other field omitted
resource::Ptr{Void}
finalize(x::SomeType) = custom_destroy(x.resource)
end As suggested, perhaps the pointer to compiled |
So that seems to limit this to being an implicit (syntactic) feature that alters the lowering of struct SomeType
#Other field omitted
resource::Ptr{Void}
finalize(x::SomeType) = custom_destroy(x.resource)
end With the the magic local function name
to
Is that worth it, or is it time to close this? |
Quite often I find myself wanting to associate a finalizer with every object of a given type (particularly to free any associated resources), and even though it is currently possible to call
finalizer
on every newly created object, but that method strikes as rather inelegant (and perhaps inefficient if the number of objects grows large). Instead I propose to add the ability to have a function applied to all objects of a given type once they are gc'd. I have something like the following in mind:Now, I'm uncertain as to the performance implication of doing a function lookup whenever an object is destroyed, but given the special nature of such a function, it might be worth thinking about adding an extra field to
jl_struct_type_t
which would hold the type finalizer (just as it does hold constructors now).The text was updated successfully, but these errors were encountered: