Daily Shaarli

All links of one day in a single page.
Fixing memory leaks in web applications | Read the Tea Leaves
thumbnail

Modern web app frameworks like React, Vue, and Svelte use a component-based model. Within this model, the most common way to introduce a memory leak is something like this:

window.addEventListener('message', this.onMessage.bind(this));

That’s it. That’s all it takes to introduce a memory leak. If you call addEventListener on some global object (the window, the , etc.) and then forget to clean it up with removeEventListener when the component is unmounted, then you’ve created a memory leak.