Weak references

333 views
Skip to first unread message

Ivan Levashew

unread,
Oct 14, 2011, 10:26:11 AM10/14/11
to General Dart Discussion
If Dart is going to target JavaScript or replace it someday, I'd like
it to have weak references. I have grepped specification for words
"weak", "raii", "finally". Hopefully Dart has try ... finally, but
still far from having weak references.

Weak references are essentional in functional-reactive programming.
Visit http://flapjax-lang.org/ , watch video at http://asana.com/luna/
to become familiar.

In FRP environments behaviors are everywhere, and they are linked
bidirectionally. When "a" changes, it notifies "a * b". In order to do
so, "a" has stored a reference to "a * b" behavior. In JavaScript
nothing will be garbage collected without an extra effort.

Extra effort is high enough e. g. introducing reference counting
overhead in an overlay language that targets JavaScript. Every closure
and every object must be reference counted to make it work. Or,
alternativelly, limiting FRP to an in-memory database semantics. In a
databases, DELETEs are explicit and so is destruction of behaviors in
the second case. Behaviors can't be used just like normal values.

Third way is to don't bother about dead data still sitting in memory
and consuming CPU. Sooner or later user will reload the page.

A fourth way... maybe we can introduce our own garbage collection in
an overlay language that targets JavaScript.

Lack of weak references results in big headache

--
If you want to get to the top, you have to start at the bottom

Gilad Bracha

unread,
Oct 14, 2011, 10:30:02 AM10/14/11
to Ivan Levashew, General Dart Discussion
Hi Ivan,

Yes, of course, we know weak references are missing in JS.  The Dart VM can address this easily. When compiling to JS, it  is more problematic. 
--
Cheers, Gilad

Tobias Ritzau

unread,
Mar 15, 2013, 5:05:27 AM3/15/13
to mi...@dartlang.org, Ivan Levashew
Bumping an old topic, but I feel that it would be a major gain if we could support weak references. Would it be an option to define a reference type that behaves differently in the VM and when compiled to js?

-- Tobias

Peter Jakobs

unread,
Mar 15, 2013, 5:57:24 AM3/15/13
to mi...@dartlang.org, Ivan Levashew
I would like weak references too. They will land in javascript in some distant future as well. Personally I have no problem with them working a bit different when they are compiled to js.
Even integer behave different when they are compiled to js.

Cheers

Peter

Tobias Ritzau

unread,
Mar 18, 2013, 8:57:45 AM3/18/13
to mi...@dartlang.org, Ivan Levashew
Really? There's only two of us??? What am I not getting?

-- Tobias

Bob Nystrom

unread,
Mar 18, 2013, 3:43:09 PM3/18/13
to General Dart Discussion, Ivan Levashew

On Fri, Mar 15, 2013 at 2:57 AM, Peter Jakobs <p4j...@gmail.com> wrote:
Even integer behave different when they are compiled to js.

This is true today, but it's not something we're happy about. It's vitally important that Dart behave predictably between the native VM and when compiled to dart2js. Current examples where it doesn't are problems to be fixed and not paths we should walk down again. :)

My impression, and I could be wrong, is that relatively few programmers know much about weak references and where they can be useful. Given that they can't currently be compiled to JavaScript and they aren't that well-known to begin with, I don't think they're a near-term priority for the team. That doesn't mean Dart will never have them, though.

Cheers,

- bob

Tobias Ritzau

unread,
Mar 19, 2013, 7:20:31 AM3/19/13
to mi...@dartlang.org, Ivan Levashew
I read, as soon as Dart has taken over the world and gained support in the major browsers we will most likely have weak reafs :) ;)

The main reason I wanted right now is because it is really easy to subscribe to things, but you really have to take care to unsubscribe or you will end up with leaks. This is mainly since you have to have the StreamSubscription object to cancel. Maybe we can work something out that makes it easier to unsubscribe while waiting for weak refs? As it is right now you should collect all StreamSubscriptions in a collection and cancel them when unbinding.

-- Tobias

Anders Holmgren

unread,
Aug 5, 2014, 7:20:46 PM8/5/14
to mi...@dartlang.org
Resurrecting an old previously resurrected topic.

Now that dart is ruling the world on the server ;-) this is a very useful feature to consider there. Just putting it out there

Reply all
Reply to author
Forward
0 new messages