How to do something before object destruction in Dart?

Dongyu Jia picture Dongyu Jia · Jul 27, 2015 · Viewed 7.9k times · Source

In Java we can do something like override finalize(), in C++ we can do something like ~Someclass(),

But How can I do it in dart, I read the doc in https://www.dartlang.org/ but did not find answers.

Answer

Günter Zöchbauer picture Günter Zöchbauer · Jul 27, 2015

This is not supported. There is nothing like a destructor in Dart.
JS garbage collector doesn't provide a way to implement this. See also https://stackoverflow.com/a/20490161/217408 and https://github.com/dart-lang/sdk/issues/3691