--0016e6d77cc87a63fc048716420e
Content-Type: text/plain; charset=ISO-8859-1

On Fri, May 21, 2010 at 1:35 AM, timr <timrandg / gmail.com> wrote:

> I was playing around looking at ObjectSpace in irb and was astounded
> at how many string objects there are. Why are there 57,000+ String
> objects?!?
>
> hash  }
> ObjectSpace.each_object.collect{|t| t.class}.uniq.each{|cla| hash[cla]
>  bjectSpace.each_object(cla).to_a.length}
> hash
>
> {Tiger, Gem::SourceIndex, Gem::Version01, String7656,
> RubyToken::TkNL, Gem::Dependency06, Proc27, NoMemoryError,
> UnboundMethod, IRB::WorkSpace, Rational0, Mutex,
> Thread, IO, Object4965, Binding, Array761, Float8,
> OptionParser::Switch::NoArgument,
> IRB::Notifier::CompositeNotifier, Range1, Bignum, fatal,
> OptionParser::OptionMap, Gem::CommandManager, IRB::Locale,
> RubyLex::TerminateLineInput, Date::Infinity,
> Gem::Requirement54, SystemStackError, Module95, Hash30,
> YAML::Syck::Resolver, ThreadGroup, Gem::Specification73,
> IRB::SLex, Gem::GemPathSearcher, File, Class38,
> IRB::Notifier::LeveledNotifier, RubyToken::TkLPAREN,
> OptionParser::List, OptionParser::CompletingHash,
> RubyToken::TkRBRACE, Enumerable::Enumerator0, Method,
> IRB::ReadlineInputMethod, IRB::StdioOutputMethod, RubyLex,
> IRB::SLex::Node8, Gem::ConfigFile, MatchData,
> IRB::Context, Regexp53, IRB::Notifier::NoMsgNotifier,
> IRB::Irb, Gem::Version::Part81, Time76}
>
>
> And if I do:
>
> ObjectSpace.each_object(String).each{|str| hash[str.object_id]  tr}
>
> I find that most of these strings appear to be paths to ruby files. I
> am curious if everyone has a similarly large set of string objects in
> their ObjectSpace, or is this a result of my personalized setup?
>
>
Using your code, in irb:
MRI 1.8.7 36715
MRI 1.9.1 3752
Rubinius 1.0 4797
MacRuby 0.6 3013

And your code didn't work in JRuby 1.5.0, or MRI 1.8.6


However, outside of irb, using
ruby -e "hash  } ; ObjectSpace.each_object.collect{|t|
t.class}.uniq.each{|cla| hash[cla] ObjectSpace.each_object(cla).to_a.length} ; p hash[String]"

I got:
MRI 1.8.7 126
MRI 1.9.1 1708
Rubinius 1.0 3424
MacRuby 0.6 1120

--0016e6d77cc87a63fc048716420e--