You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/07/27 09:21:26 UTC
[echarts] 01/01: fix(memory): reduce memory when chart instance is
still hold after dispose
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch optimize-dispose
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 648ee384914631f86ea1d116c1a088690deaee70
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Jul 27 17:20:43 2021 +0800
fix(memory): reduce memory when chart instance is still hold after dispose
---
src/core/echarts.ts | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/core/echarts.ts b/src/core/echarts.ts
index f3f21ed..5265fbe 100644
--- a/src/core/echarts.ts
+++ b/src/core/echarts.ts
@@ -1122,20 +1122,37 @@ class ECharts extends Eventful<ECEventDefinition> {
modelUtil.setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
- const api = this._api;
- const ecModel = this._model;
+ const chart = this;
+ const api = chart._api;
+ const ecModel = chart._model;
- each(this._componentsViews, function (component) {
+ each(chart._componentsViews, function (component) {
component.dispose(ecModel, api);
});
- each(this._chartsViews, function (chart) {
+ each(chart._chartsViews, function (chart) {
chart.dispose(ecModel, api);
});
// Dispose after all views disposed
- this._zr.dispose();
-
- delete instances[this.id];
+ chart._zr.dispose();
+
+ // Set properties to null.
+ // To reduce the memory cost in case the top code still holds this instance unexpectedly.
+ chart._dom =
+ chart._model =
+ chart._chartsMap =
+ chart._componentsMap =
+ chart._chartsViews =
+ chart._componentsViews =
+ chart._scheduler =
+ chart._api =
+ chart._zr =
+ chart._throttledZrFlush =
+ chart._theme =
+ chart._coordSysMgr =
+ chart._messageCenter = null;
+
+ delete instances[chart.id];
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org