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

Fixed object states memory leak #6984

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ interface ConflictMappingElement {
conflict: QualityConflict;
}

function geometryListener(setGeometry: (param: Canvas['geometry']) => void, canvasInstance: Canvas): void {
setGeometry(canvasInstance.geometry);
}

export default function IssueAggregatorComponent(): JSX.Element | null {
const dispatch = useDispatch();
const [expandedIssue, setExpandedIssue] = useState<number | null>(null);
Expand Down Expand Up @@ -74,19 +78,16 @@ export default function IssueAggregatorComponent(): JSX.Element | null {
if (canvasReady) {
const { geometry: updatedGeometry } = canvasInstance;
setGeometry(updatedGeometry);
const listener = geometryListener.bind(null, setGeometry, canvasInstance);

const geometryListener = (): void => {
setGeometry(canvasInstance.geometry);
};

canvasInstance.html().addEventListener('canvas.zoom', geometryListener);
canvasInstance.html().addEventListener('canvas.fit', geometryListener);
canvasInstance.html().addEventListener('canvas.reshape', geometryListener);
canvasInstance.html().addEventListener('canvas.zoom', listener);
canvasInstance.html().addEventListener('canvas.fit', listener);
canvasInstance.html().addEventListener('canvas.reshape', listener);

return () => {
canvasInstance.html().removeEventListener('canvas.zoom', geometryListener);
canvasInstance.html().removeEventListener('canvas.fit', geometryListener);
canvasInstance.html().addEventListener('canvas.reshape', geometryListener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it was the mistake. We need removeEventListener here. No need to change other things

canvasInstance.html().removeEventListener('canvas.zoom', listener);
canvasInstance.html().removeEventListener('canvas.fit', listener);
canvasInstance.html().addEventListener('canvas.reshape', listener);
};
}

Expand Down
Loading