Skip to content

Commit 397047e

Browse files
committed
fix: [PROD-14470] fix some risks of memory leaks
1 parent 3a5374b commit 397047e

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/views/Simulation/components/Scene/Scene.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTheme } from '@mui/styles';
55
import { useSimulationViewContext } from '../../SimulationViewContext';
66
import { DEFAULT_UPDATE_STATE } from '../../SimulationViewHook';
77
import { resetGraphHighlighting } from '../../utils/graphUtils';
8-
import { createApp, destroyApp, initApp, initMinimap, renderElements } from '../../utils/pixiUtils';
8+
import { createApp, destroyApp, initApp, initMinimap, renderElements, freeDisplayMemory } from '../../utils/pixiUtils';
99
import { ChartTimeline } from '../Charts';
1010
import { Minimap } from './Minimap';
1111

@@ -100,11 +100,7 @@ const Scene = () => {
100100
requiredUpdateStepsRef.current.layout ||
101101
requiredUpdateStepsRef.current.render
102102
) {
103-
if (sceneContainerRef.current) {
104-
sceneContainerRef.current.removeChildren().forEach((child) => {
105-
child.destroy({ children: true, texture: false, baseTexture: false });
106-
});
107-
}
103+
if (sceneContainerRef.current) freeDisplayMemory(sceneContainerRef.current);
108104

109105
const resetBounds = requiredUpdateStepsRef.current.all || requiredUpdateStepsRef.current.layout;
110106
renderElements(sceneContainerRef, graphRef, setSelectedElementId, settings, resetBounds);

src/views/Simulation/utils/MinimapContainer.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ export class MinimapContainer extends Container {
1717
this.dragTarget = null;
1818
}
1919

20+
freeDisplayMemory() {
21+
this.children.forEach((child) => {
22+
child.destroy({
23+
children: true,
24+
texture: true,
25+
context: true,
26+
style: true,
27+
});
28+
});
29+
}
30+
2031
renderElements() {
21-
this.removeChildren().forEach((child) => child.destroy({ children: true }));
32+
this.freeDisplayMemory();
2233
this.miniSceneContainer = this.forgeContainer(this.sceneContainerRef.current);
2334

2435
this.addChild(this.miniSceneContainer);
@@ -53,7 +64,8 @@ export class MinimapContainer extends Container {
5364
createScreenCursor() {
5465
if (this.screenCursor != null) {
5566
this.removeChild(this.screenCursor);
56-
this.screenCursor.destroy({ children: true });
67+
this.screenCursor.destroy({ children: true, texture: true, context: true, style: true });
68+
this.screenCursor = null;
5769
}
5870

5971
this.screenCursor = new Graphics();

src/views/Simulation/utils/pixiUtils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,22 @@ const generateTextures = (app) => {
411411
return textures;
412412
};
413413

414+
export const freeDisplayMemory = (container) => {
415+
container.children.forEach((child) => {
416+
child.destroy({
417+
children: true,
418+
texture: true,
419+
context: true,
420+
style: true,
421+
});
422+
});
423+
};
424+
414425
export const renderElements = (sceneContainerRef, graphRef, setSelectedElementId, settings, resetBounds = true) => {
415426
if (!graphRef.current || !sceneContainerRef.current?.textures) return;
416427

428+
freeDisplayMemory(sceneContainerRef.current);
429+
417430
const { nodes, links } = graphRef.current;
418431
const textures = sceneContainerRef.current.textures;
419432

0 commit comments

Comments
 (0)