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

I have some processing which isn't necessarily cpu-intensive, but lots of temporary objects are cr

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744801941a4594545.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信