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
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:
- Allocate the needed memory
- Read and write the allocated memory
- Release the memory as soon as it’s not needed anymore.