Use auto-subscriptions in Svelte 3 to avoid memory leaks when using Stores

Share this video with your friends

Send Tweet

It's important to avoid memory leaks, and Svelte 3 is no exception. When we're using the subscribe method from Svelte store in a component, it's important to clean ofter ourselves (especially if we're going to instantiate and destroy this component many times over).

In this lesson we're going to learn how to use unsubscribe to stop subscribing to the store change in a component's onDestroy call, as well how to use auto-subscriptions to refer to the store value and let Svelte take care of cleaning after us to avoid memory leaks.