Skip to content

Commit

Permalink
Fix memory leak, see #76
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Apr 6, 2022
1 parent 5d1a098 commit 51c36fd
Showing 1 changed file with 27 additions and 39 deletions.
66 changes: 27 additions & 39 deletions js/common/view/CAVScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class CAVScreenView extends ScreenView {
model.objectGroup.elementDisposedEmitter.addListener( casObject => {
const viewNode = map.get( casObject )!;
objectNodeGroup.disposeElement( viewNode );
map.delete( casObject );
} );

this.topCheckboxGroup = new TopRepresentationCheckboxGroup( model, merge( {
Expand All @@ -182,26 +183,26 @@ class CAVScreenView extends ScreenView {
} );
this.addChild( this.playAreaMedianIndicatorNode );

const updateMedianNode = () => {
const medianValue = model.medianValueProperty.value;
const visible = medianValue !== null && model.isShowingPlayAreaMedianProperty.value;

if ( visible ) {

// if there is a ball at that location, go above the ball
const ballsAtLocation = model.objectGroup.filter( casObject => casObject.valueProperty.value === medianValue );
const modelHeight = ballsAtLocation.length * model.objectType.radius * 2; // assumes no spacing

const viewHeight = this.modelViewTransform.modelToViewDeltaY( modelHeight );

this.playAreaMedianIndicatorNode.centerX = this.modelViewTransform.modelToViewX( medianValue );
this.playAreaMedianIndicatorNode.bottom = this.modelViewTransform.modelToViewY( 0 ) + viewHeight;
}
this.playAreaMedianIndicatorNode.visible = visible;
};
model.medianValueProperty.link( updateMedianNode );
model.objectChangedEmitter.addListener( updateMedianNode );
model.isShowingPlayAreaMedianProperty.link( updateMedianNode );
// const updateMedianNode = () => {
// const medianValue = model.medianValueProperty.value;
// const visible = medianValue !== null && model.isShowingPlayAreaMedianProperty.value;
//
// if ( visible ) {
//
// // if there is a ball at that location, go above the ball
// const ballsAtLocation = model.objectGroup.filter( casObject => casObject.valueProperty.value === medianValue );
// const modelHeight = ballsAtLocation.length * model.objectType.radius * 2; // assumes no spacing
//
// const viewHeight = this.modelViewTransform.modelToViewDeltaY( modelHeight );
//
// this.playAreaMedianIndicatorNode.centerX = this.modelViewTransform.modelToViewX( medianValue );
// this.playAreaMedianIndicatorNode.bottom = this.modelViewTransform.modelToViewY( 0 ) + viewHeight;
// }
// this.playAreaMedianIndicatorNode.visible = visible;
// };
// model.medianValueProperty.link( updateMedianNode );
// model.objectChangedEmitter.addListener( updateMedianNode );
// model.isShowingPlayAreaMedianProperty.link( updateMedianNode );

this.medianPredictionNode = new PredictionNode( model.medianPredictionProperty, this.modelViewTransform, model.physicalRange, {
center: this.layoutBounds.center,
Expand All @@ -219,32 +220,15 @@ class CAVScreenView extends ScreenView {
} );

this.resetAllButton = new ResetAllButton( {
listener: () => {
this.interruptSubtreeInput(); // cancel interactions that may be in progress

model.reset();

// hide the dragIndicatorArrowNode and reset the flag for if it has been dragged already
objectHasBeenDragged = false;
dragIndicatorArrowNode.visible = false;
},
listener: this.doReset.bind( this ),
right: this.layoutBounds.maxX - CAVConstants.SCREEN_VIEW_X_MARGIN,
bottom: this.layoutBounds.maxY - CAVConstants.SCREEN_VIEW_Y_MARGIN,
tandem: options.tandem.createTandem( 'resetAllButton' )
} );

this.eraseButton = new EraserButton( {
tandem: options.tandem.createTandem( 'eraseButton' ),
listener: () => {

// Interrupt dragging of existing objects
this.interruptSubtreeInput();

model.clearData();

// hide the dragIndicatorArrowNode but don't reset objectHasBeenDragged
dragIndicatorArrowNode.visible = false;
},
listener: this.doReset.bind( this ),
iconWidth: 26,
right: this.resetAllButton.left - CAVConstants.SCREEN_VIEW_X_MARGIN,
centerY: this.resetAllButton.centerY
Expand All @@ -259,6 +243,10 @@ class CAVScreenView extends ScreenView {
*/
step( dt: number ): void {
}

doReset(): void {
this.model.reset();
}
}

centerAndVariability.register( 'CAVScreenView', CAVScreenView );
Expand Down

0 comments on commit 51c36fd

Please sign in to comment.