2

Sorry for the beginner question, but this is one where I'm a bit confused, and couldn't find documentation about. So I understand that if you subscribe to an observable, it can cause memory leaks if not unsubscribed from (for example in OnDestroy since I use mainly Angular). But, is it still a problem if you close the tab/page? As I'm aware of, the server which the app is on is not running it, just serves the frontend code to the browser, which then runs/loads it. So if you don't unsubscribe properly from an observable, it should still be "destroyed" after you close the tab that the app is running on, right? I'm not sure how the browser manages to store these exactly, so I'm not 100% in this, but it sounds logical to me, since apps are most of the time not running 24/7, it's only a problem where it does run all day long, right? (And yes I know we should unsubscribe everytime, I just ask this because of my curiosity).

Puffin
  • 31
  • 2
  • 2
    Closing the tab/page should result in the release of *everything* associated with that page (maybe not *right away*, but quickly enough), regardless of any bugs in the code on that page. This depends on individual browser implementations. –  Apr 07 '21 at 15:59

1 Answers1

0

Similar questions were asked before: with rxjs and angular, Is it necessary to unsubscribe for the subscriptions that happen only once in app component's onInit method?

Also here is an explanation in which the memory leaks are reproduced and why it was necessary to unsubscribe. I have taken the code present on that url and added it to stackblitz for reference. You can uncomment the code to unsubscribe the observable and refresh the url.

The conclusion that I understood from this is after closing the tab, there should not be any memory leaks.

wahab memon
  • 2,193
  • 2
  • 10
  • 23