Skip to content

Commit 1e79d88

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

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ export class MinimapContainer extends Container {
1818
}
1919

2020
renderElements() {
21-
this.removeChildren().forEach((child) => child.destroy({ children: true }));
21+
if (this.miniSceneContainer)
22+
this.miniSceneContainer.destroy({ children: true, texture: true, context: true, style: true });
2223
this.miniSceneContainer = this.forgeContainer(this.sceneContainerRef.current);
2324

25+
this.destroy({ children: true, texture: true, context: true, style: true });
2426
this.addChild(this.miniSceneContainer);
2527

2628
this.position.set(0, 0);
@@ -53,7 +55,8 @@ export class MinimapContainer extends Container {
5355
createScreenCursor() {
5456
if (this.screenCursor != null) {
5557
this.removeChild(this.screenCursor);
56-
this.screenCursor.destroy({ children: true });
58+
this.screenCursor.destroy({ children: true, texture: true, context: true, style: true });
59+
this.screenCursor = null;
5760
}
5861

5962
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 destroyContainerChildren = (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+
destroyContainerChildren(sceneContainerRef.current);
429+
417430
const { nodes, links } = graphRef.current;
418431
const textures = sceneContainerRef.current.textures;
419432

0 commit comments

Comments
 (0)