You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to me, that although there is a destroy() method available in the API to cleanup everything before removing the input the datepicker is applied to, to avoid memory leaks, there remain references to event handlers in JQuery objects, specifically for 'resize' and 'touchstart' event handlers, and this keeps the GC from throwing the datepicker instance out of memory.
Open up Chrome Dev Tools, click on Profiles and create a new heap snapshot.
Click on Toggle button, the input - to which the datepicker is applied to - appears.
Click on Toggle, now the input disappears and we expect that everything is cleaned up.
Take a second heap snapshot.
Click on Toggle again, the input appears.
Click on Toggle to destroy the input.
Take the last heap snapshot.
Now if you list the objects which were created between the 1. and 2. snapshots (these are the objects which should not be there, because the GC should have cleaned them up) you can see that there is a $.Zebra_Datepicker instance, because the 'resize' event handler is referenced from JQuery:
I have found the cause of the problem. JQuery does not match the handler for the 'resize' event when you call $(window).unbind() for 'resize' event:
handleObj.namespace does not match the regular exp. in tmp
It does not match because of the comma at the end of the namespace, I think.
The same problem arises when you register the event handler for 'mousedown' and 'touchstart' events and the event names are separated with comma.
When I split up the event handler registration in like manner for both 'resize' and 'orientationchange' and for 'mousedown' and 'touchstart' then the memory leak goes away (zebra_datepicker.src.js ~1417. row):
`
//whenever anything is clicked on the page
var mouseDownAndTouchStartHandler = function (e) {
// if the date picker is visible
if (datepicker.hasClass('dp_visible')) {
// if the calendar icon is visible and we clicked it, let the onClick event of the icon to handle the event
// (we want it to toggle the date picker)
if (plugin.settings.show_icon && $(e.target).get(0) === icon.get(0)) return true;
// if what's clicked is not inside the date picker
// hide the date picker
if ($(e.target).parents().filter('.Zebra_DatePicker').length === 0) plugin.hide();
}
};
$(document).bind('mousedown.Zebra_DatePicker_' + uniqueid, mouseDownAndTouchStartHandler);
$(document).bind('touchstart.Zebra_DatePicker_' + uniqueid, mouseDownAndTouchStartHandler);
`
I've found another problem which connects to this closely. In the destroy() method you do not unbind the event handler for 'touchstart' event, this causes another memory leak.
The text was updated successfully, but these errors were encountered:
It seems to me, that although there is a destroy() method available in the API to cleanup everything before removing the input the datepicker is applied to, to avoid memory leaks, there remain references to event handlers in JQuery objects, specifically for 'resize' and 'touchstart' event handlers, and this keeps the GC from throwing the datepicker instance out of memory.
Steps to produce the leak (in Chrome):
I have found the cause of the problem. JQuery does not match the handler for the 'resize' event when you call $(window).unbind() for 'resize' event:
![image](https://cloud.githubusercontent.com/assets/18262711/14248587/a8784998-fa75-11e5-92a2-2e7ae8a67a62.png)
handleObj.namespace does not match the regular exp. in tmp
It does not match because of the comma at the end of the namespace, I think.
The same problem arises when you register the event handler for 'mousedown' and 'touchstart' events and the event names are separated with comma.
When I split up the event handler registration in like manner for both 'resize' and 'orientationchange' and for 'mousedown' and 'touchstart' then the memory leak goes away (zebra_datepicker.src.js ~1417. row):
`
//whenever anything is clicked on the page
var mouseDownAndTouchStartHandler = function (e) {
`
I've found another problem which connects to this closely. In the destroy() method you do not unbind the event handler for 'touchstart' event, this causes another memory leak.
The text was updated successfully, but these errors were encountered: