By Hemanta Sundaray on 2021-07-16
Let’s talk about memory management in JavaScript.
Regardless of the programming language, the memory life cycle can be understood in 3 steps:
JavaScript automatically allocates memory when values are declared initially.
// allocates memory for a number
let num = 2604;
// allocates memory for a string
let str = “hemanta”
We use memory when we read and write in allocated memory. This can be done, for example, by reading and writing the value of a variable or an object property or even passing an argument to a function.
At this stage, JavaScript utilizes a form of automatic memory management known as garbage collection. The purpose of a garbage collector is to monitor memory allocation and determine when a block of allocated memory is no longer needed and reclaim it.