Skip to content
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

Disposable problems #433

Closed
zepumph opened this issue Apr 4, 2023 · 5 comments
Closed

Disposable problems #433

zepumph opened this issue Apr 4, 2023 · 5 comments

Comments

@zepumph
Copy link
Member

zepumph commented Apr 4, 2023

From phetsims/scenery#1494 (comment) @pixelzoom said:

In #1494 (comment), one of my concerns about Disposable and the direction of this issue was:

(4) It requires a new "base class of everything"

Today I took a not-too-close look at Dispoable, and so far I've found:

And this issue is currently unassigned!

In its current state, Disposable is kind of scary. And since it's the base class of PhetioObject, cleaning this up should be high (top?) priority. Raising priority and labeling for dev meeting discussion.

I agree! Let's clean up disposer and its usages, since we aren't going to use this among the above.

@zepumph
Copy link
Member Author

zepumph commented Apr 4, 2023

Questions:

  • Should a passed in disposeEmitter be disposed on dispose? I don't think so, since it goes against how we always handle dependency injection and disposal.

@pixelzoom
Copy link
Contributor

pixelzoom commented Apr 4, 2023

Should a passed in disposeEmitter be disposed on dispose? ...

I don't understand why setDisposeEmitter is provided -- it's an unnecessary convenience, and only raises questions like this. My vote is to remove this feature. But if you choose to keep it, no, Disposable should not dispose of anything that it did not instantiate.

A couple of other things with Disposable:

  • Unless there's a use case for instantiating Disposable directly, the constructor should be protected.
  • All of the fields should be documented.

zepumph added a commit to phetsims/fourier-making-waves that referenced this issue Apr 4, 2023
zepumph added a commit to phetsims/circuit-construction-kit-common that referenced this issue Apr 4, 2023
zepumph added a commit to phetsims/ratio-and-proportion that referenced this issue Apr 4, 2023
zepumph added a commit that referenced this issue Apr 4, 2023
@zepumph
Copy link
Member Author

zepumph commented Apr 4, 2023

I am really liking this cleanup. There were 37 usages of disposer, and each one felt like it was an obfuscating pattern, not assisting with much.

I believe I have done all items that @pixelzoom has mentioned, and I confirmed that there is no memory leak when creating 40 keyboard help dialogs in Ratio and Proportion (only 2MB increase)

@pixelzoom
Copy link
Contributor

Changes look really great, thanks for doing this.

I'm not entirely sure if this._isDisposed = true should be done after this._disposeEmitter.emit(). I can imagine a listener checking isDisposed and getting confused. But you documented it well:

  // Marked true when this Disposable has had dispose() called on it (after disposeEmitter is fired)
  private _isDisposed = false;

... so I guess leave it as is?

Back to @zepumph in case there's anything else to be done.

@pixelzoom pixelzoom assigned zepumph and unassigned pixelzoom Apr 4, 2023
@zepumph
Copy link
Member Author

zepumph commented Apr 4, 2023

Great thought! After a discussion with @samreid a week ago or so, I feel like it makes sense that the flag is for "i have completely disposed" and not "I am currently disposing" which is much more challenging to calculate and to utilize effectively. We actually removing an exact assertion that you are mentioning, and instead reorganized the callback to guarantee that the view would only dispose once the model had already disposed fully.

I'm going to close this. Thanks for the speedy review.

@zepumph zepumph closed this as completed Apr 4, 2023
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

2 participants