How can you get Callback.dispose to be called?

I am looking at the js-interop library ( http://www.dartlang.org/articles/js-dart-interop/ ) and ( http://dart-lang.github.com/js-interop/docs/js/Callback. html ). I want to set up a multiple lights callback using new Callback.many

. It says that I must make sure to call dispose()

, otherwise I might get a memory leak. What's the best way to make sure what's dispose()

called when my page is unloaded?

+3


source to share


1 answer


You really don't need to explicitly remove the Callback when your page unloads. The browser has to clear them like other javascript variables used on the page.

dispose () should be used when you know the Callback will no longer be used. It's like removing a reference to an unused object to allow it to be garbage collected.



Technically, all callbacks refer to the map to allow data exchange between js and dart. Therefore, even if your code does not reference the callback, it will not be garbage collected. The call dispose()

will remove this link and make the callback free for garbage collection.

+1


source







All Articles