Is it necessary to unsubscribe from observables created by Http methods?

前端 未结 9 1663
醉酒成梦
醉酒成梦 2020-11-22 04:50

Do you need to unsubscribe from Angular 2 http calls to prevent memory leak?

 fetchFilm(index) {
        var sub = this._http.get(`http://example.com`)
              


        
9条回答
  •  盖世英雄少女心
    2020-11-22 05:20

    You should definitely read this article. It shows you why you should always unsubscribe even from http.

    If after creating the request but before receiving an answer from the back-end you deem the component unnecessary and destroy it, your subscription will maintain the reference to the component thus creating a chance for causing memory leaks.

    Update

    The above affirmation seems to be true, but anyway, when the answer comes back the http subscription is destroyed anyway

提交回复
热议问题