34

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.

user2864740
  • 60,010
  • 15
  • 145
  • 220
Dongyu Jia
  • 417
  • 1
  • 4
  • 6
  • If you are using angular-dart, DetachAware can help you. Implement your component from DetachAware and override detach method. – ashokd Aug 21 '15 at 18:18

2 Answers2

33

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

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
5

Dart now provides finalizers, as of Dart 2.17.

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70