Just curious to know how to list all the symbols used in a running ruby process? eventually want to know the size taken by all those symbols, and is there any limit on that or how to keep it limited or whether one should worry about them when size is too much
To see them all:
Symbol.all_symbols
reference: http://ruby-doc.org/core-2.1.1/Symbol.html#method-c-all_symbols
I'm not sure how to find out how much memory they are using, or if there is a limit. But, since they are never garbage collected, you SHOULD worry a bit about them. In particular, you should never allow untrusted user input to be turned into a symbol - this can be used to run your application out of memory.
For an example of turning user input into symbols, imagine a rails action which turns a user-supplied string into a symbol:
def some_action my_sym = params[:p].to_sym # ... end
Now someone can fill your ruby process space with as many symbols as they like by requesting millions of urls like
http://your_app/some_action?p=a
http://your_app/some_action?p=b
http://your_app/some_action?p=c
...
Possibly (depending on lots of things) killing your server when it runs out of memory.
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