Reputation: 55555
What triggers a JavaScript garbage collector to run? Obviously this varies by JS engines, but trying to get a rough idea. Is it only when available memory is below a certain threshold?
Thanks.
Upvotes: 1
Views: 626
Reputation: 35054
It really varies very widely. SpiderMonkey, for example, will GC based on various heuristics about how much memory has been allocated, but the browser embedding also triggers GC in various situations like after enough DOM events have been processed, after a script has run for long enough, some things to do with tabs/windows being closed or loaded, etc, etc. And the heuristics involved have changed wildly between different Firefox releases, and will change again.
And that's all for just one browser.
Upvotes: 2
Reputation:
It varies. Chrome (V8) is simply based on a timer and an activity monitor (it tries not to run when the engine is busy).
Upvotes: 2
Reputation: 57709
This varies per browser and as far as I know you have absolutely no control over it.
Likewise you have no control over when the DOM is getting rendered, which is really annoying if you want to show a loading bar :D
Why do you want to know this?
Upvotes: 0