How to create a memory leak in Angular

explore the most common cause of memory leaks in Angular apps — learn how to fix them and to avoid them in the future

Kevin Kreuzer
Angular In Depth

--

AngularInDepth is moving away from Medium. More recent articles are hosted on the new platform inDepth.dev. Thanks for being part of indepth movement!

Performance is crucial to the success of a web application. As a developer, it’s essential to know how memory leaks are created and how to deal with them.

This knowledge is especially important once your application reaches a certain size. If you aren’t careful about memory leaks, then you may end up in a “memory-leak taskforce”. (Yes, I have also been part of one 😉).

Memory leaks can have multiple sources. However, we believe that in Angular, there’s a pattern to the most common cause of memory leaks. And, there’s also a way to avoid them.

What is memory management

In JavaScript memory is managed automatically. This memory life cycle usually consists of three steps:

  1. Allocate the needed memory
  2. Read and write the allocated memory
  3. Release the memory as soon as it’s not needed anymore.

--

--

Kevin Kreuzer
Angular In Depth

Passionate freelance frontend engineer. ❤️ Always eager to learn, share and expand knowledge.