How to make an object disposable in Dart?

566 views Asked by At

I have an abstract class named AbstractFoo and its implementation, Foo. Foo also implements an interface Bar. I would like to make Foo disposable so I assume that I need to implement Disposable class but I am getting an error

Classes and mixins can only implement other classes and mixins

I tried to make AbstractFoo implement Disposable but I get the same error. Can anyone help?

1

There are 1 answers

1
Chuck Batson On

There is no automatic disposal system built into Dart. You are referencing the w_common package.

According to the page you linked, you will need to define classes you want to be disposed something like this:

class MyDisposable extends Object with Disposable {
   MyDisposable() {
     var thing = new ThingThatRequiresCleanup();
     getManagedDisposer(() {
       thing.cleanUp();
       return new Future(() {});
     });
   }
 }

For more specific help, please edit your question to include code.