Skip to content

Commit

Permalink
Address memory leak, see: #38
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Jun 23, 2022
1 parent fdf38ba commit 9a65aa1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/intro/view/WaterCup3DNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export default class WaterCup3DNode extends Node {
private readonly waterLevelTriangle: WaterLevelTriangleNode;
private readonly cup3DModel: WaterCupModel;
private readonly adapterProperty: NumberProperty;
private readonly introModel: IntroModel;
private readonly showTickMarksLink: ( isShowingTickMarks: boolean ) => void;

public constructor( introModel: IntroModel, cup3DModel: WaterCupModel, modelViewTransform: ModelViewTransform2,
providedOptions?: WaterCup3DNodeOptions ) {
providedOptions?: WaterCup3DNodeOptions ) {

const options = optionize<WaterCup3DNodeOptions, SelfOptions, NodeOptions>()( {
y: modelViewTransform.modelToViewY( 0 ) - MeanShareAndBalanceConstants.CUP_HEIGHT,
Expand All @@ -40,6 +42,7 @@ export default class WaterCup3DNode extends Node {
super();

this.cup3DModel = cup3DModel;
this.introModel = introModel;

// The CUP_HEIGHT is the height of the 2d cups. The 3D cups have to be adjusted accordingly because of the top and bottom ellipses,
// so they don't seem disproportionately tall
Expand All @@ -56,7 +59,9 @@ export default class WaterCup3DNode extends Node {
beakerGlareFill: MeanShareAndBalanceColors.waterCup3DGlareFillColorProperty
} );

introModel.isShowingTickMarksProperty.link( isShowingTickMarks => waterCup.setTicksVisible( isShowingTickMarks ) );
this.showTickMarksLink = ( isShowingTickMarks: boolean ) => waterCup.setTicksVisible( isShowingTickMarks );

introModel.isShowingTickMarksProperty.link( this.showTickMarksLink );

// adapterProperty double-checks the constraints and deltas in the water levels between the 2D and 3D cups.
// when the adapterProperty values change a method in the introModel compares delta between current and past value
Expand Down Expand Up @@ -90,14 +95,14 @@ export default class WaterCup3DNode extends Node {

this.addChild( waterCup );
this.addChild( this.waterLevelTriangle );

this.mutate( options );
}

public override dispose(): void {
super.dispose();
this.waterLevelTriangle.dispose();
this.adapterProperty.dispose();
this.introModel.isShowingTickMarksProperty.unlink( this.showTickMarksLink );
this.cup3DModel.resetEmitter.removeAllListeners();
}
}
Expand Down

0 comments on commit 9a65aa1

Please sign in to comment.