Skip to content

Commit 2b1f66c

Browse files
author
Jelte Lagendijk
committed
Possible memory leak fix
1 parent 16052ff commit 2b1f66c

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"generatorVersion": "2.0.1",
2626
"paths": {
27-
"testProjectFolder": "./test/",
27+
"testProjectFolder": "C:\\Projects\\MendixProjects\\GC-Test-main\\",
2828
"testProjectFileName": "[Test] ChartJS.mpr"
2929
},
3030
"scripts": {

src/ChartJS/widgets/Core.js

Lines changed: 28 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,33 @@ 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.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+
}
245+
}
246+
247+
if (this._chartEntityObject !== null) {
248+
logger.debug(this.id + ".uninitialize release obj " + this._chartEntityObject.getGuid());
249+
mx.data.release(this._chartEntityObject);
250+
}
251+
}
227252
},
228253

229254
customTooltip: function (tooltip) {

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

Lines changed: 1 addition & 0 deletions
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({

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

Lines changed: 1 addition & 0 deletions
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({

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

155 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)