Skip to content

Commit bc89ec8

Browse files
committed
fix(core): prevent memory leaks in table cleanup
1 parent f575d75 commit bc89ec8

5 files changed

Lines changed: 99 additions & 26 deletions

File tree

common/config/rush/pnpm-lock.yaml

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-disable */
2+
import * as VTable from '../../src';
3+
import VChart from '@visactor/vchart';
4+
import { bindDebugTool } from '../../src/scenegraph/debug-tool';
5+
6+
const CONTAINER_ID = 'vTable';
7+
VTable.register.chartModule('vchart', VChart);
8+
export function createTable() {
9+
const option = {
10+
columns: [
11+
{ field: 'id', title: 'ID', width: 80 },
12+
{ field: 'name', title: '姓名', width: 120 },
13+
{ field: 'age', title: '年龄', width: 80 },
14+
{ field: 'city', title: '城市', width: 120 }
15+
],
16+
records: Array.from({ length: 10000 }, (_, i) => ({
17+
id: i,
18+
name: `张三${i}`,
19+
age: i,
20+
city: `城市${i}`
21+
}))
22+
};
23+
// document.getElementById(CONTAINER_ID).parentElement.style.display = 'none';
24+
let tableInstance = new VTable.ListTable(document.getElementById(CONTAINER_ID), option);
25+
// window.tableInstance = instance;
26+
27+
// tableInstance.onVChartEvent('mouseover', args => {
28+
// console.log('listenChart mouseover', args);
29+
// });
30+
31+
// bindDebugTool(tableInstance.scenegraph.stage, {
32+
// customGrapicKeys: ['col', 'row']
33+
// });
34+
35+
const update = async () => {
36+
// 执行20次release / new
37+
for (let i = 0; i < 20; i++) {
38+
await new Promise(resolve => setTimeout(resolve, 200));
39+
// // tableInstance.release();
40+
// // instance.scenegraph.component.vScrollBar.release();
41+
// // instance.scenegraph.component.hScrollBar.release();
42+
// // instance.scenegraph.stage.removeAllChild();
43+
// // delete instance.scenegraph.stage.table;
44+
// // instance.scenegraph.clearCells();
45+
// tableInstance.scenegraph.component.vScrollBar.release();
46+
// tableInstance.scenegraph.component.hScrollBar.release();
47+
// tableInstance.animationManager.clear();
48+
// tableInstance.animationManager.ticker.release();
49+
// // instance.animationManager.ticker = null;
50+
// // instance.animationManager = null;
51+
// tableInstance.scenegraph.stage.ticker.release();
52+
tableInstance.release();
53+
tableInstance = null;
54+
await new Promise(resolve => setTimeout(resolve, 200));
55+
tableInstance = new VTable.ListTable(document.getElementById(CONTAINER_ID), option);
56+
console.log(`第${i}次new完成`);
57+
}
58+
};
59+
60+
window.update = update;
61+
// update();
62+
}

packages/vtable/examples/menu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const menus = [
2525
{
2626
path: 'debug',
2727
name: 'scroll'
28+
},
29+
{
30+
path: 'debug',
31+
name: 'mem'
2832
}
2933
]
3034
},

packages/vtable/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
},
5454
"dependencies": {
5555
"@visactor/vtable-editors": "workspace:*",
56-
"@visactor/vrender-core": "~1.0.40",
57-
"@visactor/vrender-kits": "~1.0.40",
58-
"@visactor/vrender-components": "~1.0.40",
59-
"@visactor/vrender-animate": "~1.0.40",
56+
"@visactor/vrender-core": "~1.0.41-alpha.2",
57+
"@visactor/vrender-kits": "~1.0.41-alpha.2",
58+
"@visactor/vrender-components": "~1.0.41-alpha.2",
59+
"@visactor/vrender-animate": "~1.0.41-alpha.2",
6060
"@visactor/vutils": "~1.0.17",
6161
"@visactor/vscale": "~1.0.17",
6262
"@visactor/vdataset": "~1.0.17",
@@ -133,4 +133,4 @@
133133
"url": "https://github.com/VisActor/VTable.git",
134134
"directory": "packages/vtable"
135135
}
136-
}
136+
}

packages/vtable/src/core/BaseTable.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,13 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
26102610
* @returns {void}
26112611
*/
26122612
release(): void {
2613+
// for memory leak of VRender Event
2614+
this.scenegraph?.component?.vScrollBar?.release();
2615+
this.scenegraph?.component?.hScrollBar?.release();
2616+
this.animationManager.clear();
2617+
this.animationManager.ticker.release();
2618+
this.scenegraph?.stage?.ticker?.release();
2619+
26132620
const internalProps = this.internalProps;
26142621
if (this.isReleased) {
26152622
return;

0 commit comments

Comments
 (0)