bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Datepicker leaks memory when used in presence of jquery

Open ankit5990 opened this issue 12 years ago • 7 comments

When datepicker is used in an application which has jQuery included as well, then datepicker is seen to leak memory.

The scope of the controller on which datepicker is used is seen to leak when an investigation of heap is done.

I have created a plunker to show this issue. http://embed.plnkr.co/qRZEMgBRNIBRjE1fTcCM/ On repeatedly opening and closing a page with datepicker on it, leaks memory which is never reclaimed on GC cycle. screenshot 2014-09-03 19 04 17

ankit5990 avatar Sep 03 '14 13:09 ankit5990

+1

cyrilwiz avatar Sep 04 '14 05:09 cyrilwiz

+1

karora23 avatar Sep 04 '14 06:09 karora23

Thanks for posting this. I've done some investigation to this. It looks like an AngularJS bug with jQuery's cache. It's jQuery's caching that's keeping the references to the scopes. The newest AngularJs version seems to have fixed most of the leaking.

Your Plunker (Angular 1.2.10): screen shot 2014-09-03 at 11 48 22 pm

Angular 1.3.0-beta.14: screen shot 2014-09-03 at 11 42 16 pm

Angular 1.3.0-rc.0: screen shot 2014-09-03 at 11 43 02 pm

Notice there are differences in the y-axis scaling, but look at the "Selected Size" value.

Here's the Plunker I used: http://plnkr.co/edit/MupMyWCj4oMUonz5EMA7?p=preview

chrisirhc avatar Sep 04 '14 06:09 chrisirhc

+1

suyash1208 avatar Sep 04 '14 06:09 suyash1208

+1

ashishgoyal86 avatar Sep 04 '14 07:09 ashishgoyal86

I have made the fix in the code for this issue. Its a very small fix, datepickerPopup directive creates a popupElement div in the code which needed to be removed. I have created plunkers for comparison.

Plunk without fix:- http://embed.plnkr.co/CYV8uXKv1O7ODkFroee4/

Plunk after fix:- http://embed.plnkr.co/buFTsQp7TMsbNRlKXTKf/preview

Memory usage before fix- before fix

Memory usage after fix- after fix

I would like to contribute the change back to the library. @chrisirhc can you help me on how to submit a PR?

ankit5990 avatar Sep 10 '14 13:09 ankit5990

Created a pull request for the fix https://github.com/angular-ui/bootstrap/pull/2684

ankit5990 avatar Sep 10 '14 13:09 ankit5990