Skip to content

Commit 26672c4

Browse files
author
Jelte Lagendijk
committed
Fix issue #92, adding onDestroy Microflow for widgets, removing Chart Entity fixes memory leak
1 parent 208cf07 commit 26672c4

File tree

9 files changed

+314
-268
lines changed

9 files changed

+314
-268
lines changed

src/ChartJS/widgets/BarChart/BarChart.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@
248248
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Datapoint object 'Data point entity'</description>
249249
<returnType type="Void"></returnType>
250250
</property>
251+
<property key="onDestroyMf" type="microflow" required="false" entityProperty="sourceentity">
252+
<caption>On Destroy Microflow</caption>
253+
<category>Behavior</category>
254+
<description>Microflow to be called when the widget is destroyed. This can be used to destroy the Chart Entity from 'Data Source'.
255+
256+
Note: This is experimental. In case of non-persistent objects this should not be necessary, and in MX 7 this is useless. Only use this if you experience memory leaks in Mendix 5</description>
257+
<returnType type="Void"></returnType>
258+
</property>
251259
<!-- Settings -->
252260
<property key="responsive" type="boolean" required="true" defaultValue="true">
253261
<caption>Responsive</caption>

src/ChartJS/widgets/Core.js

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

7777
_tooltipNode: null,
7878

79-
_chartEntityObject: null,
80-
8179
startup: function () {
8280
logger.debug(this.id + ".startup");
8381

@@ -188,8 +186,6 @@ define([
188186
return;
189187
}
190188

191-
this._chartEntityObject = obj;
192-
193189
// Retrieve datasets
194190
mx.data.get({
195191
guids: guids,
@@ -233,7 +229,6 @@ define([
233229
dataset = null;
234230

235231
this._data.object = obj;
236-
this._chartEntityObject = obj;
237232

238233
// Retrieve datasets
239234
mx.data.get({
@@ -293,13 +288,16 @@ define([
293288
}
294289
}
295290

296-
if (this._chartEntityObject !== null) {
297-
logger.debug(this.id + ".uninitialize release obj " + this._chartEntityObject.getGuid());
298-
mx.data.release(this._chartEntityObject);
299-
}
300-
301291
if (this._data.object && this._data.object.getGuid) {
302-
mx.data.release(this._data.object);
292+
if (this.onDestroyMf) {
293+
this._executeMicroflow(this.onDestroyMf, lang.hitch(this, function () {
294+
logger.debug(this.id + ".uninitialize release obj " + this._data.object.getGuid());
295+
mx.data.release(this._data.object);
296+
}), this._data.object);
297+
} else {
298+
logger.debug(this.id + ".uninitialize release obj " + this._data.object.getGuid());
299+
mx.data.release(this._data.object);
300+
}
303301
}
304302
}
305303
},
@@ -659,7 +657,7 @@ define([
659657
},
660658

661659
_executeMicroflow: function (mf, callback, obj) {
662-
logger.debug(this.id + "._executeMicroflow");
660+
logger.debug(this.id + "._executeMicroflow " + mf);
663661
var _params = {
664662
applyto: "selection",
665663
actionname: mf,

src/ChartJS/widgets/DoughnutChart/DoughnutChart.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@
211211
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
212212
<returnType type="Void"></returnType>
213213
</property>
214+
<property key="onDestroyMf" type="microflow" required="false" entityProperty="sourceentity">
215+
<caption>On Destroy Microflow</caption>
216+
<category>Behavior</category>
217+
<description>Microflow to be called when the widget is destroyed. This can be used to destroy the Chart Entity from 'Data Source'.
218+
219+
Note: This is experimental. In case of non-persistent objects this should not be necessary, and in MX 7 this is useless. Only use this if you experience memory leaks in Mendix 5</description>
220+
<returnType type="Void"></returnType>
221+
</property>
214222
<!-- Settings -->
215223
<property key="responsive" type="boolean" required="true" defaultValue="true">
216224
<caption>Responsive</caption>

src/ChartJS/widgets/PieChart/PieChart.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@
213213
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
214214
<returnType type="Void"></returnType>
215215
</property>
216+
<property key="onDestroyMf" type="microflow" required="false" entityProperty="sourceentity">
217+
<caption>On Destroy Microflow</caption>
218+
<category>Behavior</category>
219+
<description>Microflow to be called when the widget is destroyed. This can be used to destroy the Chart Entity from 'Data Source'.
220+
221+
Note: This is experimental. In case of non-persistent objects this should not be necessary, and in MX 7 this is useless. Only use this if you experience memory leaks in Mendix 5</description>
222+
<returnType type="Void"></returnType>
223+
</property>
216224
<!-- Settings -->
217225
<property key="responsive" type="boolean" required="true" defaultValue="true">
218226
<caption>Responsive</caption>

src/ChartJS/widgets/PolarChart/PolarChart.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@
203203
<description>Microflow to invoke when chart canvas is clicked. This Microflow will pass the Dataset object 'Data set entity'</description>
204204
<returnType type="Void"></returnType>
205205
</property>
206+
<property key="onDestroyMf" type="microflow" required="false" entityProperty="sourceentity">
207+
<caption>On Destroy Microflow</caption>
208+
<category>Behavior</category>
209+
<description>Microflow to be called when the widget is destroyed. This can be used to destroy the Chart Entity from 'Data Source'.
210+
211+
Note: This is experimental. In case of non-persistent objects this should not be necessary, and in MX 7 this is useless. Only use this if you experience memory leaks in Mendix 5</description>
212+
<returnType type="Void"></returnType>
213+
</property>
206214
<!-- Settings -->
207215
<property key="responsive" type="boolean" required="true" defaultValue="true">
208216
<caption>Responsive</caption>

src/ChartJS/widgets/RadarChart/RadarChart.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@
103103
<description>Microflow returning a 'Chart Entity' object.</description>
104104
<returnType type="Object" entityProperty="sourceentity"></returnType>
105105
</property>
106+
<property key="onDestroyMf" type="microflow" required="false" entityProperty="sourceentity">
107+
<caption>On Destroy Microflow</caption>
108+
<category>Behavior</category>
109+
<description>Microflow to be called when the widget is destroyed. This can be used to destroy the Chart Entity from 'Data Source'.
110+
111+
Note: This is experimental. In case of non-persistent objects this should not be necessary, and in MX 7 this is useless. Only use this if you experience memory leaks in Mendix 5</description>
112+
<returnType type="Void"></returnType>
113+
</property>
106114
<!--<property key="sourceTrigger" type="attribute" entityProperty="sourceentity" allowNonPersistableEntities="true" required="false">
107115
<caption>Attribute to trigger</caption>
108116
<category>Data Set</category>

0 commit comments

Comments
 (0)