-
Notifications
You must be signed in to change notification settings - Fork 12
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
Node's dispose isn't called often #601
Comments
I added in the Node.prototype.dispose.call(this) into many of the instrumented sun and scenery-phet classes. It would be nice to check that other node subclasses address this. |
I've started using this pattern to future-proof implementations of dispose: function() {
SuperType.prototype.dispose && SuperType.prototype.dispose.call( this );
this.disposeSubType();
} The advantage of the above approach is that I don't have to go hunting for dispose functions in the type hierarchy -- which are sometime not at all easy to find, due to mixins or non-intutivie hierarchies (Node extends Events being a prime example). The disadvantage of the above approach is that I don't identify supertypes that should have a dispose function and are therefore leaking memory. Another disadvantage is that, a future implementation of the supertype's dispose may break my code. So when you add a dispose function to a type, don't assume that you don't need to test! There may be code that starts to use your new dispose function as soon as it's added. |
Generally, the order should be reversed: dispose: function() {
this.disposeSubType();
SuperType.prototype.dispose && SuperType.prototype.dispose.call( this );
} That is, the order an object is disassembled should be the reverse of the order the object is assembled. For instance, if subType does this.children.push(x) and subType dispose does this.children.remove(x), that must be done before the SuperType eliminates the children array. |
Self assigned to look at |
@jonathanolson said:
In 2/9/17 dev meeting, he said there's a better way to do this, and he'll do it. |
I took care of my sims, and all common-code except:
I intended to handle these sometime in the next week. |
I completed common-code, see above commits. |
All devs: Highly recommended to address this issue in your sims. You can wait until @jonathanolson implements automated checking. Or you can manually inspect First, identify whether the supertype has a For example,
If the supertype does have a dispose: function() {
this.disposeSubType();
SuperType.prototype.dispose.call( this );
} If the supertype does not have a dispose: function() {
this.disposeSubType();
SuperType.prototype.dispose && SuperType.prototype.dispose.call( this );
} |
Checks for repeated disposal or not calling Node.dispose()
…rriding Node's dispose (and we wouldn't want to call that). See phetsims/scenery#601
Issues created for locations that still have this problem, and since it seems to be helpful long-term, I'll leave in the assertion checks to make sure Node.dispose() is called (and that it isn't called twice). |
A ton of types are overriding dispose() on Node and not calling the Node.prototype.dispose(). It has always existed, but was just part of Events which had a no-op dispose() method, but now (with the Tandem handling) it actually does something.
Flagging for developer meeting for handling. I'll check to see whether I can identify where this happens by toString()ing functions automatically.
The text was updated successfully, but these errors were encountered: