I create a lot of dynamic components using:
this.factory = this.componentFactoryResolver.resolveComponentFactory(SliderComponent);
this.sliderComponentReference = viewContainerRef.createComponent(this.factory);
When I need the component destroyed I call the destroy method:
this.sliderComponentReference.destroy();
I understand that it deleted the dynamic component from the view and it's instance however when I view the variable right after I notice it still has information:
changeDetectorRef: ViewRef_ {_view: {…}, _viewContainerRef: ViewContainerRef.. }
componentType:(...)
hostView: ViewRef_ {_view: {…}, _viewContainerRef: ViewContainerRef... }}
injector:(...)
Questions:
How come the variable still has reference to the component instance if it was destroyed?
Is the component still stored in memory? If so is it retrievable?
this.sliderRef.destroy(); console.log(this.sliderRef)?