From: Robert Dober on
I would rather count like this
jruby -X+O -ve 'p ObjectSpace.each_object(String).count'
jruby 1.5.0.RC3 (ruby 1.8.7 patchlevel 249) (2010-05-05 6586) (OpenJDK
Client VM 1.6.0_0) [i386-java]
519
ruby -ve 'p ObjectSpace.each_object(String).count'
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
164
ruby -ve 'p ObjectSpace.each_object(String).count'
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]
2268

HTH
R.

From: Charles Oliver Nutter on
JRuby master for your little script with ObjectSpace on:

~/projects/jruby ➔ jruby -X+O c.rb
210 String
152 Class
16 Module
5 Float
4 Array
3 Hash
3 IO
2 Object
1 Binding
1 Thread
1 ThreadGroup

Note that even with it on we don't track a lot of transient objects in
ObjectSpace, so there's potentially others floating around not shown
here.

- Charlie

On Fri, May 21, 2010 at 4:51 AM, Robert Klemme
<shortcutter(a)googlemail.com> wrote:
> 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