优化内存泄露的问题

This commit is contained in:
CN-JS-HuiBai
2026-04-06 02:09:34 +08:00
parent d7b6d3aebb
commit 607d71d1ca
3 changed files with 78 additions and 18 deletions

View File

@@ -16,10 +16,11 @@ class AreaChart {
this.dpr = window.devicePixelRatio || 1;
this.padding = { top: 20, right: 16, bottom: 32, left: 56 };
this.currentMaxVal = 0;
this.prevMaxVal = 0;
this.currentMaxVal = 0;
this._resize = this.resize.bind(this);
// Use debounced resize for performance and safety
this._resize = typeof debounce === 'function' ? debounce(this.resize.bind(this), 100) : this.resize.bind(this);
window.addEventListener('resize', this._resize);
this.resize();
}
@@ -335,7 +336,8 @@ class MetricChart {
this.prevMaxVal = 0;
this.currentMaxVal = 0;
this._resize = this.resize.bind(this);
// Use debounced resize for performance and safety
this._resize = typeof debounce === 'function' ? debounce(this.resize.bind(this), 100) : this.resize.bind(this);
window.addEventListener('resize', this._resize);
this.resize();
}