jquery / jquery/jquery-ui

Datepicker Memory Leak

Open
#2,280 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Behavior shared with 1.12 Comp: Datepicker
Dominant language
JavaScript
Stars
11.3k
Forks
5.2k
PR merge metrics
No merged PRs in 30d

Description

Building off #2268, there is a problem when destroying the datepicker where it doesn’t completely get removed from memory. This pull request, https://github.com/jquery/jquery-ui/commit/817ce38, removes the instance reference but the actual UI reference is tied to

https://github.com/jquery/jquery-ui/blob/54f96eea31b21d9ecb00912261df3e5aaebf8cce/ui/widgets/datepicker.js#L163

When the widget is destroyed, the datepicker UI element remains in memory preventing it from closing. https://github.com/jquery/jquery-ui/pull/2268 patches this issue by hiding the component, however dpDiv is still in memory. One solution could be to remove dpDiv from the instance and then set both _curInst = null and this.dpDiv = null.
https://github.com/jquery/jquery-ui/pull/2268/commits/5e4f1b86296c5a977abc7efaff671ea9004d4d37
However, many unit tests will break because they rely on dpDiv to still exist in memory, requiring the datepicker to be recreated for each test. There is also a problem that many developers rely on hiding the datepicker before destroying it $.datepicker("hide").destroy("destroy") which will fail because dpDiv will be null.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect ui/widgets/datepicker.js around line 163 and trace the destroy path described in the issue. Review the unit tests that rely on dpDiv and reproduce the hide-then-destroy sequence. Done means the datepicker UI is no longer retained after destruction while the affected tests and documented usage behavior are addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, jquery
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.