Skip to content

Commit

Permalink
fix leaks related to NumberPicker and EquationNode, #153
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Apr 9, 2024
1 parent 6a59f6f commit e6a8bbf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
10 changes: 8 additions & 2 deletions js/common/view/EquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ export default class EquationNode extends Node {
const minRiseNode = new SlopePicker( new Property( riseRangeProperty.value.min ),
new Property( runRangeProperty.value.max ), riseRangeProperty, pickerOptions );

const maxRunNode = new SlopePicker(
new Property( runRangeProperty.value.max ),
const maxRunNode = new SlopePicker( new Property( runRangeProperty.value.max ),
new Property( riseRangeProperty.value.max ), runRangeProperty, pickerOptions );

const minRunNode = new SlopePicker( new Property( runRangeProperty.value.min ),
Expand All @@ -125,6 +124,13 @@ export default class EquationNode extends Node {
// Compute the max width
const maxRiseWidth = Math.max( maxRiseNode.width, minRiseNode.width );
const maxRunWidth = Math.max( maxRunNode.width, minRunNode.width );

// Clean up the NumberPicker instances, because they link to a LocalizedStringProperty for PDOM.
maxRiseNode.dispose();
minRiseNode.dispose();
maxRunNode.dispose();
minRunNode.dispose();

return Math.max( maxRiseWidth, maxRunWidth );
}
}
Expand Down
14 changes: 8 additions & 6 deletions js/linegame/view/GraphTheLineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ export default class GraphTheLineNode extends ChallengeNode {
} );

// Answer
const answerBoxNode = new EquationBoxNode( GraphingLinesStrings.lineToGraphStringProperty, challenge.answer.color, boxSize,
ChallengeNode.createEquationNode( new Property<Line | NotALine>( challenge.answer ), challenge.equationForm, {
fontSize: LineGameConstants.STATIC_EQUATION_FONT_SIZE,
slopeUndefinedVisible: false
} ) );
const answerEquationNode = ChallengeNode.createEquationNode( new Property<Line | NotALine>( challenge.answer ), challenge.equationForm, {
fontSize: LineGameConstants.STATIC_EQUATION_FONT_SIZE,
slopeUndefinedVisible: false
} );
const answerBoxNode = new EquationBoxNode( GraphingLinesStrings.lineToGraphStringProperty, challenge.answer.color,
boxSize, answerEquationNode );

const guessLineProperty = new Property<Line | NotALine>( Line.Y_EQUALS_X_LINE ); // start with any non-null line
const guessEquationNode = ChallengeNode.createEquationNode( guessLineProperty, challenge.equationForm, {
Expand Down Expand Up @@ -165,12 +166,13 @@ export default class GraphTheLineNode extends ChallengeNode {

this.disposeGraphTheLineNode = () => {
titleText.dispose();
answerEquationNode.dispose();
guessEquationNode.dispose();
answerBoxNode.dispose();
guessBoxNode.dispose();
this.notALineText.dispose();
challenge.guessProperty.unlink( guessObserver );
model.playStateProperty.unlink( playStateObserver );
guessEquationNode.dispose();
this.graphNode.dispose();
};
}
Expand Down
12 changes: 7 additions & 5 deletions js/linegame/view/MakeTheEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export default class MakeTheEquationNode extends ChallengeNode {
} );

// Answer
const answerBoxNode = new EquationBoxNode( GraphingLinesStrings.aCorrectEquationStringProperty, challenge.answer.color, boxSize,
ChallengeNode.createEquationNode( new Property<Line | NotALine>( challenge.answer ), challenge.equationForm, {
fontSize: LineGameConstants.STATIC_EQUATION_FONT_SIZE
} ) );
const answerEquationNode = ChallengeNode.createEquationNode( new Property<Line | NotALine>( challenge.answer ), challenge.equationForm, {
fontSize: LineGameConstants.STATIC_EQUATION_FONT_SIZE
} );
const answerBoxNode = new EquationBoxNode( GraphingLinesStrings.aCorrectEquationStringProperty, challenge.answer.color,
boxSize, answerEquationNode );
answerBoxNode.visible = false;

// Guess
Expand Down Expand Up @@ -147,9 +148,10 @@ export default class MakeTheEquationNode extends ChallengeNode {
titleText.dispose();
answerBoxNode.dispose();
guessBoxNode.dispose();
answerEquationNode.dispose();
guessEquationNode.dispose();
challenge.guessProperty.unlink( guessObserver );
model.playStateProperty.unlink( playStateObserver );
guessEquationNode.dispose();
graphNode.dispose();
};
}
Expand Down

0 comments on commit e6a8bbf

Please sign in to comment.