Reputation: 39
I'm building a Dart app which contains a variety of class objects. The particular class object I'm dealing with contains a variety of stream event listeners on DOM elements. When I remove these objects from the DOM and untrack the class object these listeners persist.
I know that Dart runs garbage collection eventually, but I'm not even 100% sure it will come along and delete these class objects since there is a Watcher and Stream listeners that continue.
My question is, is there a way to actively delete a class object immediately? I tried setting the class object to null but that doesn't seem to work for some reason. When I check if the object exists afterward with a print statement, it still lists it as an instance of that class object.
Furthermore, for what I'm trying to accomplish, canceling streams doesn't seem to be enough. I need to destroy the class object.
Upvotes: 2
Views: 1821
Reputation: 657178
Setting references to null
is all you can do. Your test seems very weird. How can you print the object if you don't have a reference? If you still have a reference, how can you expect the instance to be collected.
Upvotes: 2