ngu-carousel icon indicating copy to clipboard operation
ngu-carousel copied to clipboard

Memory leak problem due to Renderer2's createElement() method

Open raymond-coinx opened this issue 6 years ago • 4 comments

I noticed that there is a memory leak problem using ngu-carousel. When i switch from one component from another componet, the componet that contains ngu-carousel could never be garbage collected.

So I dig into this issue and I found that it was caused by the code const styleItem = this._renderer.createElement('style'); in _createStyleElem method. According to the discuss - Memory leak issue due to Renderer2's .createElement() method, we need to destroy the element generated by this._renderer.createElement if no longer needed.

Then I try to add reference to each element generated by createElement and destroy them in ngOnDestroy method, the memory leak problem gone. Example code:

 ngOnDestroy() {
  ...
  // Destroy this.carouselCssNode generated by createElement
  this.renderer.removeChild(document.body, this.carouselCssNode);
  this.renderer.destroyNode(this.carouselCssNode)
  this.carouselCssNode= null;
}

I try the above code in angular 5.2 and ngu-carousel 1.4.8. I did not try the latest code because I need to use static items in the carousel but I believe the bug still exists in the latest version.

raymond-coinx avatar Feb 14 '19 09:02 raymond-coinx

Hi @raymond-coinx ,

Thanks for reporting. will fix this in upcoming version. FYI: Please check this demo to create a static carousel with latest version

sheikalthaf avatar Mar 04 '19 09:03 sheikalthaf

I am also facing the same issue. I am using the latest version of ^1.5.5 and with dynamic items. Appreciate if you can provide me any temporary solution until it has been fixed in the upcoming version.

Thanks

bhagath007 avatar Aug 14 '19 12:08 bhagath007

Same Issue while switching from one component to another, Expecting a quick fix for this issue, Its disgusting.

sameerthekhans avatar Aug 16 '19 03:08 sameerthekhans

Even I am facing same issue. Can anyone help me atleast with any temporary solution.

amit509 avatar Aug 16 '19 04:08 amit509

Does this one fixed in version 2.02?

ElesGergo avatar Apr 08 '20 10:04 ElesGergo