Do I have to unsubscribe from ActivatedRoute (e.g. params) observables?

前端 未结 5 878
既然无缘
既然无缘 2020-12-01 10:17

I find many examples where ActivatedRoute Observables like params or url are subscribed but not unsubscribed.

construc         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 10:31

    The component will be destroyed and the routerState will become unreferenced when the router navigates to a different route, which will make them free to get garbage collected including the observable.

    If you pass around references to this component to other components or services, the component won't be garbage collected and the subscription would be kept active, but I'm sure (without verifying) that the observable will be completed by the router when navigating away and cause the subscription to cancel.

提交回复
热议问题