Skip to content

Commit 3089208

Browse files
author
Jelte Lagendijk
committed
Merge branch 'fix/memoryleak'
2 parents 21bf097 + d33cf50 commit 3089208

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

src/ChartJS/widgets/Core.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ define([
7676

7777
_tooltipNode: null,
7878

79+
_chartEntityObject: null,
80+
7981
startup: function () {
8082
logger.debug(this.id + ".startup");
8183

@@ -142,12 +144,13 @@ define([
142144
this._mxObj = obj;
143145

144146
if (this._handle !== null) {
145-
mx.data.unsubscribe(this._handle);
147+
this.unsubscribe(this._handle);
146148
this._handle = null;
147149
}
148150

149151
if (this._mxObj) {
150-
this._handle = mx.data.subscribe({
152+
logger.debug(this.id + ".update obj " + this._mxObj.getGuid());
153+
this._handle = this.subscribe({
151154
guid: this._mxObj.getGuid(),
152155
callback: lang.hitch(this, this._loadData)
153156
});
@@ -184,6 +187,8 @@ define([
184187
return;
185188
}
186189

190+
this._chartEntityObject = obj;
191+
187192
// Retrieve datasets
188193
mx.data.get({
189194
guids: guids,
@@ -217,13 +222,46 @@ define([
217222

218223
uninitialize: function () {
219224
logger.debug(this.id + ".uninitialize");
225+
226+
//console.log(this._data);
220227
if (this._handle !== null) {
221-
mx.data.unsubscribe(this._handle);
228+
this.unsubscribe(this._handle);
222229
}
223230

224231
if (this._tooltipNode) {
225232
domConstruct.destroy(this._tooltipNode);
226233
}
234+
235+
if (mx.data.release && !mx.version || mx.version && parseInt(mx.version.split(".")[0]) < 7) { // mx.data.release is deprecated in MX7, so this is for MX5 & MX6
236+
if (this._data && this._data.datasets && this._data.datasets.length > 0) {
237+
logger.debug(this.id + ".uninitialize release datasets");
238+
for (var i = 0; i < this._data.datasets.length; i++) {
239+
var data = this._data.datasets[i];
240+
if (data.dataset && data.dataset.getGuid) {
241+
logger.debug(this.id + ".uninitialize release dataset obj " + data.dataset.getGuid());
242+
mx.data.release(data.dataset);
243+
}
244+
if (data.points && data.points.length > 0) {
245+
for (var j = 0; j < data.points.length; j++) {
246+
var point = data.points[j];
247+
if (point && point.getGuid) {
248+
logger.debug(this.id + ".uninitialize release datapoint " + point.getGuid());
249+
mx.data.release(point);
250+
}
251+
}
252+
}
253+
}
254+
}
255+
256+
if (this._chartEntityObject !== null) {
257+
logger.debug(this.id + ".uninitialize release obj " + this._chartEntityObject.getGuid());
258+
mx.data.release(this._chartEntityObject);
259+
}
260+
261+
if (this._data.object && this._data.object.getGuid) {
262+
mx.data.release(this._data.object);
263+
}
264+
}
227265
},
228266

229267
customTooltip: function (tooltip) {

src/ChartJS/widgets/DoughnutChart/widget/DoughnutChart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ define([
6868
dataset = null;
6969

7070
this._data.object = obj;
71+
this._chartEntityObject = obj;
7172

7273
// Retrieve datasets
7374
mx.data.get({
@@ -135,7 +136,7 @@ define([
135136
}));
136137

137138
// Set the con
138-
html.set(this._numberNode, this._data.object.get(this.numberInside));
139+
html.set(this._numberNode, this._data.object.get(this.numberInside).toString());
139140

140141
// Add class to determain chart type
141142
this._addChartClass("chartjs-doughnut-chart");

src/ChartJS/widgets/PieChart/widget/PieChart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ define([
6767
dataset = null;
6868

6969
this._data.object = obj;
70+
this._chartEntityObject = obj;
7071

7172
// Retrieve datasets
7273
mx.data.get({
@@ -137,7 +138,7 @@ define([
137138
this._chart = new this._chartJS(this._ctx, chartProperties);
138139

139140
// Set the con
140-
html.set(this._numberNode, this._data.object.get(this.numberInside));
141+
html.set(this._numberNode, this._data.object.get(this.numberInside).toString());
141142

142143
// Add class to determain chart type
143144
this._addChartClass("chartjs-pie-chart");

src/ChartJS/widgets/PolarChart/widget/PolarChart.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ define([
6969
dataset = null;
7070

7171
this._data.object = obj;
72+
this._chartEntityObject = obj;
7273

7374
// Retrieve datasets
7475
mx.data.get({

test/widgets/ChartJS.mpk

354 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)