5.10 Garbage Collection
In low-level languages like C or C ++, when creating an object, we need to Allocate memory to it, and when we are done, we need to Reallocate memory. But in JavaScript, we don't have this concept. We can easily create the new object, at the time we initialized this object, the memory is automatically allocated to this object, then we can use it, and when we are done using, we don't need to deallocate the memory. So our JavaScript engine has what we call the garbage collector. The job of this garbage collector is to find variables or constants that are no longer in use, and then deallocate the memory that was previously allocated to them. The memory allocation and deallocation happens automatically behind the scenes, and you have no control over it. You can't tell the garbage collector when to run and which variables to delete from memory. So, based on complex algorithms, this garbage collector runs in the background, it determines which variables are not used, and then it will automatically deallocate their memory. In low-level languages like C or C++, when we create an object, we have to allocate memory to it, and when we are done, we have to reallocate memory. But in JavaScript, we don't have this concept. We can easily create the new object, at the time we initialized this object, the memory is automatically allocated to this object, then we can use it, and when we are done using, we don't need to deallocate the memory. So our JavaScript engine has what we call the garbage collector. The job of this garbage collector is to find variables or constants that are no longer in use, and then deallocate the memory that was previously allocated to them. The memory allocation and deallocation happens automatically behind the scenes, and you have no control over it. You can't tell the garbage collector when to run and which variables to delete from memory. So based on complex algorithms, this garbage collector runs in the background, it determines which variables are not used, and then it will automatically deallocate their memory. That's it for this little video about Garbage collector in JavaScript, let's meet again for a very next video.