Opened 5 years ago
Closed 3 years ago
#15270 closed bug (fixed)
Datepicker - Memory leak
Reported by: | jigar140291 | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | none |
Component: | ui.datepicker | Version: | 1.12.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I have a single page application with component programming. It has multiple pages out of which few of them have date picker in it. I found out my application was leaking and have detached nodes due to which the whole component stays in memory even after the user moves to a different page (destroying the component), GC was unable to clear it. after investigation, I found out that showdatepicker function stores the current DOM instance of datepicker to this._curInst into global space which is not getting cleared at the time of destroying datepicker, which is causing a leak.
I have created a small demo at https://jsfiddle.net/ksdsxhL1/1/
steps:
- Open date picker by clicking on the input box once and close.
- click on destroy button.
- Open debugger and take heapsnapshot under memory and look for detached nodes. out of which look for the yellow node which shows reference to _curInst variable.
Tested on: Chrome, Mozilla Firefox, IE.
Temporary fix:
On destroying component or datepicker add this line
$.datepicker._curInst = null
If you are using Angular2 for eg.
ngOnDestroy(){ $('#id').datepicker('destroy'); $.datepicker._curInst = null }
Fixed and merged: https://github.com/jquery/jquery-ui/commit/817ce38555f07981f929fb4b1229fc42574cf85c