简体   繁体   中英

JS Garbage Collector

JS GC has two spaces: the young and the old spaces. 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. 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.

The behavior you describe there is particular to a specific implementation and not a general property of the standardized javascript language.

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.

Is this variable promoted to old space directly?

That would be one possible implementation strategy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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