bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Datepicker memory leaks and detached DOM elements

Open lijuenc opened this issue 12 years ago • 14 comments

Plunkr: http://plnkr.co/edit/GJtRokCxZADkRgNwVtGY?p=preview Related? https://github.com/angular-ui/bootstrap/issues/2363

Datepicker appears to leak memory when changing routes and does not clean itself up completely when in a view where a datepicker is no longer used.

How to reproduce: Switch to route 2 Switch back to route 1 Switch to route 2 Switch back to route 1

Note that there is 1 tree of detached DOM elements related to the datepicker (using Chrome profiler). 1

Switch to route 2 Switch back to route 1 Switch to route 2 Switch back to route 1 Switch to route 2 Switch back to route 1 Switch to route 2 Switch back to route 1

Now there are several trees of detached DOM elements related to the datepicker. 2

If it was just the datepicker being retained in memory this would not be as big of a deal, but this leak causes any view that contains a datepicker to also be retained in memory. For larger views, memory usage gets out of hand very quickly,

lijuenc avatar Jul 21 '14 02:07 lijuenc

+1

amanmahajan7 avatar Aug 15 '14 22:08 amanmahajan7

+1

derek-pavao avatar Aug 20 '14 15:08 derek-pavao

+1

SergeyRolich avatar Aug 20 '14 16:08 SergeyRolich

+1

yazdog8 avatar Aug 20 '14 22:08 yazdog8

+1

stevenup7 avatar Aug 20 '14 22:08 stevenup7

I wonder why there is no any warning about causing memory leak. User expects smooth UX, but gets memory leak with crashing browser.

deedarb avatar Aug 21 '14 08:08 deedarb

Tabset also produces memory leak. Same as datepicker's scenario to reproduce memory leak.

deedarb avatar Aug 24 '14 16:08 deedarb

+1

ankit5990 avatar Aug 29 '14 14:08 ankit5990

I just attempted to reproduce this. I'm not seeing memory leaks.

The detached DOM is there only because the garbage collection (GC) hasn't run.

Using the record heap allocations option, I saw that the DOM was being cleaned up:

screen shot 2014-08-29 at 10 34 48 am

The last blue bar there shows the detached DOM that hasn't been cleaned up, but the previous gray bars were all cleaned up (hence they turn gray).

There maybe a leak but this Plunker doesn't demonstrate it. Also, please make sure you're not recording the memory profile of the Plunker app, open the embed in a new window.

Here's what I saw on the Timeline view (this doesn't correspond with the heap allocation run above, it was a separate occasion but I clicked on route 2/route 1 repeatedly as well). The last dip was when I forced GC to run (there's a button on the timeline view).

screen shot 2014-08-29 at 10 39 35 am

chrisirhc avatar Aug 29 '14 17:08 chrisirhc

It was with this plunk (running locally, not in the iframe) that I could reproduce this 100% of the time following my listed steps. I could get into the 100s of MBs if I clicked enough times.

I can no longer reproduce it today. Perhaps something within Chrome has changed between the time that I reported this and now. Consider it addressed unless someone else runs into the same issue.

lijuenc avatar Sep 01 '14 02:09 lijuenc

Just checked my chrome version on mac (latest version). Created simplest project with 3 tabs and empty controllers, one tab contains 17 datepicker elements. Click on tab with datepickers then to empty tab and again for 2-3 times. After that force GC using timeline record and press bin icon and after garbage collection take heap profile and see results of such operation screen shot 2014-09-01 at 10 40 05 am and i've disabled angular batarang (if someone suspects it)

deedarb avatar Sep 01 '14 04:09 deedarb

I see a huge memory leak when using angular bootstrap datepickerPopup, on inspecting the heap snapshots, I can see "scope.close" function of the "datepickerPopup" directive associated with detached DOM elements. In addition to this, the $parent property of the directive somehow has the entire scope object of the page on which I have used datepickerPopup. This leaked parent scope because of datepicker directive is causing huge memory leaks in my app. :(

ankit5990 avatar Sep 02 '14 18:09 ankit5990

Please open another issue if you want to demonstrate this. I need a plunker to investigate the issue.

chrisirhc avatar Sep 02 '14 21:09 chrisirhc

opened an issue #2658 with a plunker to repro the leak. I saw that leak only exists when jQuery is also included in the app.

ankit5990 avatar Sep 03 '14 13:09 ankit5990