ngu-carousel
ngu-carousel copied to clipboard
Memory leak problem due to Renderer2's createElement() method
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.
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
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
Same Issue while switching from one component to another, Expecting a quick fix for this issue, Its disgusting.
Even I am facing same issue. Can anyone help me atleast with any temporary solution.
Does this one fixed in version 2.02?