Is uncapped, dynamic creation of ES6 Symbols something that can result in irrecoverable memory usage?
In Erlang (and also previously, Ruby), creation of atoms/symbols are not garbage collected.
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.
Basically, all symbols created dynamically while Ruby is running (via to_sym , etc.) can be garbage collected because they are not being used behind the scenes inside the Ruby interpreter.
Some high-level languages, such as JavaScript, utilize a form of automatic memory management known as garbage collection (GC). The purpose of a garbage collector is to monitor memory allocation and determine when a block of allocated memory is no longer needed and reclaim it.
With a const variable declaration, you can't assign to the variable something little like "" or null to clear its contents. That's really the only difference in regard to memory management. Automatic garbage collection is not affected at all by whether it is declared const or not.
Luckily for you, Node. js comes with a garbage collector, and you don't need to manually manage memory allocation.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With