-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Finalizer vs destructor #60596
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
Comments
Dart is a garbage collected language. Objects are never really truly destroyed - they just become unreachable and disappear and the space which was occupied by them is reclaimed in bulk by GC (or more specifically by a sweeper which is a part of the GC). This means destructors don't really fit. They are a better fit for languages which use more immediate means of memory management - destroying objects immediately as the last reference to them disappears. This usually requires some blend of lexical scope based, type system based and reference counting based memory management. Swift and Objective-C are using reference counting. Rust uses affine typesystem and has Arc as a fallback for when a more complex ownership sharing is needed. Default implementations of Python and PHP are using reference counting with fallback cycle-collectors. Python's and PHP's choice to expose immediate destruction to developers ( |
Thanks for the detailed explanation. I understand why destructors don’t fit Dart’s GC model. I’ll stick with Finalizer for resource cleanup. |
Hello,
I open this issue to discuss about the Finalizers and the main concept of destructors. Finalizers smell like a small bandage on top of the language. The C++ language have the destructor concept which is (for me) cleaner, easier to use/understand and achieve if i'm not wrong the exact same behavior.
What are the benefits for Dart to use Finalizers instead of something like destructors ?
The usage feel a bit over complexe for a simple feature (maybe not technicaly, sorry !)
To use Finalizer in dart :
We need to :
To use destructor In c++ :
We need to :
If i'm not wrong other language like Rust, Python, Swift, Objective-C, PHP follow this way.
Why Dart don't use it ?
The text was updated successfully, but these errors were encountered: