0

I'm disappointed that dart doesn't feature weak references.

Is there something about compiling to a language which doesn't offer weak references which makes it impossible?

2 Answers 2

1

Yes.

In order to support weak references, you need a way to interact with or override the GC.
That is fundamentally impossible in Javascript.

Sign up to request clarification or add additional context in comments.

2 Comments

i'm not convinced. in the end, js is turing complete - as an extreme approach to supporting weak references, one could write a vm in js which implements memory management itself.
True. I should have said that it's impossible to do that within the JS host environment.
1

Dart wants to compile to performant JavaScript. That's why it needs to skip certain features (tail calls, for example). And I'd even argue that weak references are a bad idea anyway.

1 Comment

what do you dislike about weak references? i'd like to have them so that i can build an event system which doesn't easily lead to memory leaks. if event triggers could weakly reference their callbacks, this would be easier than diligently unbinding those triggers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.