Ngx-bootstrap: Memory leak caused by date picker

Created on 24 Apr 2018  路  6Comments  路  Source: valor-software/ngx-bootstrap

A component that uses the "bsDatepicker" will be hold in memory despite being destroyed.

angular. 5.2.9
ngx-bootstrap: 2.0.4

reproduce:

  • create a new Angular project and add ngx-bootstrap
  • add a 2nd component that can be navigated to
  • add a date picker to the 2nd component: <input type="text" placeholder="Datepicker" class="form-control" bsDatepicker>
  • navigate between the main component and the 2nd component

result:
multiple instances of the 2nd component resist in memory, despite they have been destroyed

image

comp(datepicker) issue

Most helpful comment

All 6 comments

ngx-bootstrap: 2.0.5
Angular: 5.x

We had also a memory leak issue due to bsDatePicker which prevents the angular component to be garbage-collected.
Our workaround has been to comment the following code in the file bs-datepicker-input.directive.js:
// update input value on locale change // this._localeService.localeChange.subscribe(function () { // _this._setInputValue(_this._value); // });

I hope that it would be useful for you.

ngx-bootstrap: 5
Angular: 7

It seems the problem still exists.

Here is a small example: https://stackblitz.com/edit/angular-n4tusz

Simply route back and forth between the components and create snapshots e.g. with the Chrome DevTools to examine the objects in the memory.

image

image

After the datepicker component has been opened several times:

image

Hi, I'm working with an application with dozens of datepickers, and this issue may cause the parent component to be retained. Of course, the memory builds up massively.

This issue has been open a while - so I'm wondering: are you not wanting to fix it as it is not regarded an issue, or simply hasn't been looked at? Happy to provide a fix if welcome :)

Hi, any news on this? Can we expect the fix from @Gbuomprisco to be merged any time soon? We are affected by this issue as well.

Hi, this memory leak is quite intense. For comparison screenshot on memory consumption chart with untouched sources and sources with localeService subscription commented out. As you can see on the first chart the memory consumption is still increasing. On second chart, after garbage collection it has the same size as at the beginning.

Original:
Screenshot 2021-03-23 at 11 01 51

Without localeService subscription:
Screenshot 2021-03-23 at 10 59 39

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hugonne picture hugonne  路  3Comments

ctrl-brk picture ctrl-brk  路  3Comments

tuoitrexuquang picture tuoitrexuquang  路  3Comments

Scooviese picture Scooviese  路  3Comments

KimBum picture KimBum  路  3Comments