最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Do web workers get their own Garbage Collector? - Stack Overflow

programmeradmin3浏览0评论

I have some processing which isn't necessarily cpu-intensive, but lots of temporary objects are created which results in unsavory Garbage Collector hiccups during animation etc.

Will offloading that temp-object creation process to web workers help alleviate that? In other words - will the GC hiccups be isolated to the web worker thread and not affect my main thread, or is GC something that will affect both threads?

I have some processing which isn't necessarily cpu-intensive, but lots of temporary objects are created which results in unsavory Garbage Collector hiccups during animation etc.

Will offloading that temp-object creation process to web workers help alleviate that? In other words - will the GC hiccups be isolated to the web worker thread and not affect my main thread, or is GC something that will affect both threads?

Share Improve this question edited Sep 11, 2017 at 14:34 davidkomer asked Sep 8, 2017 at 14:07 davidkomerdavidkomer 3,0982 gold badges29 silver badges65 bronze badges 1
  • my guess is they do but that's purely a guess – Ced Commented Sep 10, 2017 at 2:52
Add a ment  | 

1 Answer 1

Reset to default 8

The ECMAScript specification does not specify any form memory management, garbage collection is only referred to in non-normative parts.

Similarly the web worker spec does not say much about garbage collection except wrt. to how long some objects must live.

So this is implementation-specific behavior. Even if implementations implement a per-worker GC and avoid shared overhead in the general case they might still trigger a global collection of all workers due to memory pressure, especially on memory-constrained systems.

That said, it is more likely that you will achieve some GC isolation with workers than without. But you have to take care to avoid messaging overhead between workers and the main thread, since serializing messages (for the structured clone algorithm) can produce additional garbage. Using transferables or shared memory buffers can avoid this.

发布评论

评论列表(0)

  1. 暂无评论