Garbage Collection & Chrome extension
My first language was C,C++. Both of these languages do not have a garbage collector. In it, whenever you allocate some memory “dynamically”, you have to deallocate it. For normal variables like “int a”, “char str[10]”, etc, memory is automatically allocated and deallocated. For dynamically allocated memory like “int *p = new int[10]”, it is programmers responsibility to deallocate memory when no longer needed. If programmer doesn’t deallocate memory, it causes memory leak (memory is not deallocated until program terminates).
C uses malloc() and calloc() function to allocate memory dynamically at run time and uses free() function to free dynamically allocated memory. C++ supports these functions and also has two operators new and delete that perform the task of allocating and freeing the memory in a better and easier way.
Let’s talk about these higher order languages which have this beautiful concept of garbage collection. Java, Javascript, etc. There are 3 phases for memory. Allocated, Used and Deallocated. Deallocation is done by developer in C, C++ while it’s taken care by Garbage collector in CPP. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management for algorithms on how the garbage collection happens.
A beautiful tool to monitor this heap memory in chrome is Profiler. You can use this to see how the allocation and deallocation happens automatically with graphs.
My issue was, I was making a call to chrome storage to get the details on page via paginations and was logging it. So, GC was not able to deallocate the storage because of logging and after few page changes, my browser became very slow. The Deallocation was not happening and memory was continually increasing. After a lot of hit and trials, I figured out the root cause as logging in console!
You may contact the author at abhinav.rai.1996@gmail.com