From: Robert Klemme Date: 2010-05-21T18:51:26+09:00 Subject: Re: OMG, why are there so many Strings in ObjectSpace! 2010/5/21 timr : > 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?!? It would be interesting to know what code you executed *before* you created your stats. Note that this includes any libraries required and files loaded. Another question is: is there a problem? Is your program slow or running out of memory? If not, why care? Eventually all these objects will be GC'ed - unless you have a leak of course. Btw: 11:47:36 Temp$ cat c.rb cnt = Hash.new 0 ObjectSpace.each_object(Object) do |o| cnt[o.class] += 1 end cnt.sort_by {|k,v| -v}.each do |cl,count| printf "%6d %s\n", count, cl end 11:49:54 Temp$ allruby c.rb CYGWIN_NT-5.1 padrklemme1 1.7.5(0.225/5/3) 2010-04-12 19:07 i686 Cygwin ======================================== ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] 179 Class 167 String 16 Module 6 Array 5 Float 3 Object 3 IO 1 File 1 Binding 1 Hash 1 SystemStackError 1 NoMemoryError 1 Bignum 1 fatal 1 ThreadGroup 1 Thread ======================================== ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-cygwin] 1659 String 201 Class 83 Encoding 48 RubyVM::InstructionSequence 18 Module 14 Array 10 Hash 10 Regexp 5 Bignum 5 Float 3 IO 2 Object 2 RubyVM::Env 1 Binding 1 ThreadGroup 1 Thread 1 RubyVM 1 NoMemoryError 1 Complex 1 SystemStackError 1 ARGF.class 1 Mutex 1 Data 1 File 1 fatal ======================================== jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) Client VM 1.6.0_20) [x86-java] c.rb:5:in `each_object': ObjectSpace is disabled; each_object will only work with Class, pass -X+O to enable (RuntimeError) from c.rb:5 11:50:10 Temp$ Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/