简体   繁体   English

JS垃圾收集器

[英]JS Garbage Collector

JS GC has two spaces: the young and the old spaces. JS GC有两个空间:年轻空间和老空间。 Firstly, any variable allocation happens in the young space and after some of them may be promoted to the old collection. 首先,任何变量分配都发生在年轻空间中,并且在其中一些可能被提升为旧集合之后。 Young collections are limited to 1-16MB. 年轻的收藏限制为1-16MB。 I have a question: if a developer declares variable whose size is more than the size of the young space what happens? 我有一个问题:如果开发人员声明的变量大小大于年轻空间的大小,会发生什么? Is this variable promoted to old space directly? 该变量是否直接提升为旧空间?

Exactly how a garbage collector works (eg whether it uses a semi-space young generation ) is implementation-dependent, ie varies between different javascript runtimes, and not all that important unless you want to get deep into performance-optimization territory. 垃圾收集器的确切工作方式(例如,是否使用半空间年轻代 )取决于实现,即在不同的JavaScript运行时之间有所不同,并且除非您想深入了解性能优化领域,否则并不是那么重要。

The behavior you describe there is particular to a specific implementation and not a general property of the standardized javascript language. 您在此处描述的行为特定于特定的实现,而不是标准化javascript语言的一般属性。

What is important that collectors provide the behavior mandated by the specification. 收集器提供规范要求的行为很重要。 And the specification does not say anything about a specific size threshold such as 16MiB after which objects should be treated differently. 而且规范没有说明任何有关特定大小阈值(例如16MiB)的信息,在此之后应该对对象进行不同的处理。

Is this variable promoted to old space directly? 该变量是否直接提升为旧空间?

That would be one possible implementation strategy. 那将是一种可能的实施策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM