The issue is caused by Mendix who is extending the prototype of dijit widget and overwriting the destroy function. This destroy function tries to destroy all child widgets. But the calendar is generating child widgets that are not registered with this custom Mendix property _supportingWidgets and hence not destroyed.
"mxui/widget/_Widget": function() {
define(["dijit/_Widget", "dijit/registry"],
function(_Widget, registry ) {
_Widget.prototype.destroy = function(preserveDom) {
if (!this._destroyed) {
this._beingDestroyed = true;
this.uninitializer && this.uninitializer();
try {
this.uninitialize();
} catch (e) {
throw new Error(this.id + ".destroy: Some trouble in uninitialize function: " + e.message);
}
dojo.forEach(this._connects, function(con) {
dojo.forEach(con, dojo.disconnect);
});
dojo.forEach(this._subscribes, function(sub) {
dojo.unsubscribe(sub);
});
dojo.forEach(this._supportingWidgets || [], function(w) {
if (w.destroyRecursive) {
w.destroyRecursive();
} else {
if (w.destroy) {
w.destroy();
}
}
});
this.destroyRendering(preserveDom);
registry.remove(this.id);
this._destroyed = true;
}
};
});
}
@ Mendix Please find a solution for this issue. This approach limits the use of external widgets to build Mendix Custom widgets. (a support ticket 317420)
Extracted Sample in jsfiddle: https://jsfiddle.net/L1bq6h7g/2/
Mendix Support:
Our R&D department took a look at the case and told me that this will be fixed in 5.20.
Thank you!
Mendix does not immediately destroy widgets but attempts to reuse them by applying another context, when a page is displayed with another object. As DUC BUI suggested, make sure your IDs are unique where necessary.
You do need to include any widget teardown in the destroy method to avoid browser memory leaks.