是否收集了ES6全局符号垃圾? [英] Are ES6 global symbols garbage collected?

查看:78
本文介绍了是否收集了ES6全局符号垃圾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态地创建ES6符号是否会导致无法恢复的内存使用?

Is uncapped, dynamic creation of ES6 Symbols something that can result in irrecoverable memory usage?

在Erlang(以及以前的Ruby)中,原子/符号的创建不会被垃圾收集.

In Erlang (and also previously, Ruby), creation of atoms/symbols are not garbage collected.

似乎无法在全局符号注册表(Symbol.for('string'))中创建的符号被垃圾收集并在全局上保持唯一,但我可能丢失了一些内容.在我看来,这似乎不受ES6规范的约束.

It seems like Symbols created in the global symbol registry (Symbol.for('string')) could not be garbage collected and remain globally unique but I might be missing something. This did not seem to me to be dictated by the ES6 spec.

推荐答案

符号为原语并不意味着它们不能使用引用和分配来实现.只要考虑一下js中的原始字符串.浏览器可能以这种方式实现符号,从而使它们服从于gc.在chrome中进行快速测试for(;;) Symbol();(不要运行它)会导致锯齿状的内存配置文件,因此我假设已分配符号并收集了垃圾.

Symbols being primitives does not mean they cannot be implemented using references and allocation. Just think about primitive strings in js. Browsers might implement symbols this way, making them subject to gc. A quick test for(;;) Symbol(); (don't run it) in chrome causes a sawtooth memory profile so I assume symbols get allocated and garbage collected.

这篇关于是否收集了ES6全局符号垃圾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆