Garbage Collection improvements in Firefox improve memory usage
Mozilla introduced Garbage Collection in Firefox 38 that improves memory management of the web browser as part of the organization's ongoing effort to bring memory usage of the browser down and optimize it as best as possible for all use cases.
So how does compacting work in Firefox?
Memory problems arise when many arenas with few live cells each exist as the space cannot be released to memory in this case, While "dead" cell space can be used by the same kind, they cannot be used by different kinds.
Mozilla's algorithm works by moving live cells between arenas to reduce the number of arenas used by the Heap. It works by selecting appropriate cells, moving them and updating all pointers to make sure no objects or data is lost in the process.
The selection process lists all arenas with live cells in decreasing order and splits it in half to move cells out of arenas with few cells to release them to memory afterwards.
It is interesting to note that compacting triggers only on three specific events currently:
- When Firefox is running out of memory.
- When the operating system sends a "memory pressure" event.
- When the user has been inactive for a certain period of time (currently about 20 seconds)
Check how much memory free cells use
You can check how much memory cells use in Firefox.
- TypeÂ about:memory in the browser's address bar and hit enter.
- Search for js-main-runtime-gc-heap-committed
- Locate gc-things in its tree.
Additional information about the process are available on Mozilla Hacks.
There is a imbalance currently in the reporting that covers Firefox and Mozilla. Feature removals and additions get lots of publicity, usually by Firefox users opposing the change, whereas core improvements like these, that are mostly under the hood, get little to no publicity at all.
Mozilla could do a better job at promoting those under the hood improvements as those are features that are -- usually - welcome by all users of the browser.