Does Dart/Flutter have the concept of weak references?

As of 2020, I'd like to add to Günter's answer that I've just published a package that goes as close as possible to a weak-reference by implementing a weak-map and a weak-container, as well as cache functions that take advantage of weak references.

  • https://pub.dev/packages/weak_map

It's much easier to use than an Expando (it uses Expando internally).


Dart doesn't provide weak reference feature.

An Expando has a weak reference behavior though. Not sure if this is of use in your use case.

  • https://api.dartlang.org/stable/1.24.3/dart-core/Expando-class.html
  • https://groups.google.com/a/dartlang.org/forum/m/#!topic/misc/S7GGxegtJe4
  • What is the Dart "Expando" feature about, what does it do?
    https://github.com/dart-lang/sdk/issues/16172

I sometimes use a Mixin that provides a list where I can add subscriptions and a dispose methode that cancels all subscriptions and add it to widgets and other classes where I need it.