Skip to content

[isolated-workers] Have ability to call dispose on classes when destroyed for v1? #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bfgeek opened this issue Oct 16, 2015 · 4 comments

Comments

@bfgeek
Copy link
Contributor

bfgeek commented Oct 16, 2015

E.g.

[NoInterfaceObject]
interface Disposable {
  void dispose(); 
};

Spec wording:
Creating classes registered on the global scope is the responsibility user agent. To allow authors to release resources used by these classes, the user agent must call the dispose() method on the class before destroying.

The only use-case for this is shared cache-objects on the global scope, and allowing code to clean up after themselves. Is it worth putting this in v1?

E.g.

var sharedCache = null;
var sharedCacheCount = 0;
registerAClass('foo', class Foo {
  constructor() {
    sharedCacheCount++;
    if (!sharedCache) buildExpensiveCache();
  },
  dispose() {
    sharedCacheCount--;
    if (!sharedCacheCount) sharedCache = null; // Frees memory.
  }
});
@domenic
Copy link
Contributor

domenic commented Oct 16, 2015

Doesn't this violate https://w3ctag.github.io/design-principles/#js-gc

@bfgeek
Copy link
Contributor Author

bfgeek commented Oct 16, 2015

Maybe, it doesn't explicitly tell you when gc is going to occur, just "I'm never ever going to invoke you of your methods again". ¯\o/¯

@esprehn
Copy link

esprehn commented Oct 20, 2015

This is similar life cycle management as attachedCallback/detachedCallback in custom elements. dispose is the isolated worker side callback that would fire for detachedCallback.

@bfgeek
Copy link
Contributor Author

bfgeek commented Jan 31, 2016

It was decided that we should leave this type of API until V2 of worklets / paint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants