-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature Request: WeakMap #5144
Comments
This comment was originally written by @seaneagan I think that's what Expando is for: http://api.dartlang.org/docs/continuous/dart_core/Expando.html but I could be wrong. I assume it will be implemented with JS WeakMap or a polyfill thereof where necessary: |
Removed Type-Defect label. |
This comment was originally written by @seaneagan AFAIK, Expando in dart2js is not yet weak. Here is a polyfill for JS WeakMaps which could be used to fix this: https://code.google.com/p/es-lab/source/browse/trunk/src/ses/WeakMap.js |
Expando in dart2js is "weak" in the sense that adding an expando property to an object (the key) will not keep the key object alive on its own. The key will keep the value (whatever the expando property refers to) alive. Without having spent too much time looking at it, I think we're basically doing the same thing as the polyfill you refer to (we store an extra hidden property on the key). |
This comment was originally written by @seaneagan Cool. According to the polyfill docs, this approach still can have leaks |
I guess the leak is that if the Expando object dies, the properties on the objects will not be removed, which will keep the value alive. This is where it fails to implement an ephemeron table or a proper weak map. |
Is expando in dart2js weak these days? cc @floitschG. |
As weak as ever. |
Current browser support for WeakMap: http://kangax.github.io/compat-table/es6/#WeakMap |
Although IE11 has only 2/5, it looks like the 3 points are not that important (at least after a fast glance). |
Almost a year, time for a ping. |
Retains the existing code as fallback for settings without WeakMap for now. Fixes issue #5144 BUG= http://dartbug.com/5144 R=sigmund@google.com Review URL: https://codereview.chromium.org/1599393003 .
Weak references in the dart vm for Flutter would be useful. |
A "weak reference" is very different from a weak map. That said, this issue is a request for a weak map, and |
Just for reference, I've publish this package: https://pub.dev/packages/weak_map |
@marcglasberg, now that Dart is supporting WeakRef and Finalizer, it would be great to release a new version of the weak_map package that uses WeakRef and Finalizer to support iterable keys and values. |
Fyi @polina-c who may be interested in helping implement this. |
@jacob314 |
This issue was originally filed by @pjako
I would like to have weak references in dart, I know its hard to do in javascript, currently at least.
Currently I want to give an object some uniqueID and track it in a Map without preventing the object to get garbage collected.
The text was updated successfully, but these errors were encountered: