OMG, why are there so many Strings in ObjectSpace!

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]
= ObjectSpace.each_object(cla).to_a.length}
hash

{Tiger=>1, Gem::SourceIndex=>1, Gem::Version=>601, String=>57656,
RubyToken::TkNL=>1, Gem::Dependency=>206, Proc=>127, NoMemoryError=>1,
UnboundMethod=>1, IRB::WorkSpace=>1, Rational=>10, Mutex=>1,
Thread=>1, IO=>5, Object=>64965, Binding=>3, Array=>3761, Float=>18,
OptionParser::Switch::NoArgument=>2,
IRB::Notifier::CompositeNotifier=>1, Range=>51, Bignum=>2, fatal=>1,
OptionParser::OptionMap=>2, Gem::CommandManager=>1, IRB::Locale=>1,
RubyLex::TerminateLineInput=>1, Date::Infinity=>2,
Gem::Requirement=>554, SystemStackError=>1, Module=>495, Hash=>130,
YAML::Syck::Resolver=>2, ThreadGroup=>1, Gem::Specification=>173,
IRB::SLex=>1, Gem::GemPathSearcher=>1, File=>2, Class=>438,
IRB::Notifier::LeveledNotifier=>4, RubyToken::TkLPAREN=>1,
OptionParser::List=>1, OptionParser::CompletingHash=>1,
RubyToken::TkRBRACE=>1, Enumerable::Enumerator=>10, Method=>1,
IRB::ReadlineInputMethod=>1, IRB::StdioOutputMethod=>2, RubyLex=>1,
IRB::SLex::Node=>78, Gem::ConfigFile=>1, MatchData=>4,
IRB::Context=>1, Regexp=>353, IRB::Notifier::NoMsgNotifier=>1,
IRB::Irb=>1, Gem::Version::Part=>481, Time=>176}

And if I do:

ObjectSpace.each_object(String).each{|str| hash[str.object_id] = str}

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?

On Fri, May 21, 2010 at 1:35 AM, timr [email protected] wrote:

RubyToken::TkNL=>1, Gem::Dependency=>206, Proc=>127, NoMemoryError=>1,
OptionParser::List=>1, OptionParser::CompletingHash=>1,

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

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.

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
and 553 for 1.5.0

On Fri, May 21, 2010 at 8:35 AM, timr [email protected] wrote:

ObjectSpace.each_object(String).each{|str| hash[str.object_id] = str}

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?
Sorry really did not see what you were looking for, somehow missed
your post, my bad.

I checked and my string path objects are from $:, the global include
path.
Cheers
R.

Dear Andrea,

which bindings you use exactly?
What’s your OS?
Installed Qt version?
Installed Ruby version?

If you get segfault on every steps your bindings are not corresponding
to installed Qt version.
Project is not dead.

Regards,
Jan

Am 21.05.2010 10:49, schrieb Andrea D.:

project: I am more than willing to help fixing the bugs, just I don’t
have the time for learning my way through the codebase from scratch. The
project seems dead to me, I couldn’t find a single “real world”
application using the bindings.

Thanks in advance!


Jan P.
Otto Group · GroupTechnologyPartner - Dresden (GTP)
Touchpoints& Kunde · FI-IM-TK

GroupTechnologyPartner - Dresden GmbH · Freiberger Straße 35 · 01067
Dresden
Telefon +49 (0) 351 497 23 202 · Fax +49 (0) 351 497 23 119

[email protected] · www.ottogroup.com


AG Dresden, HRB 2475
Geschäftsführer: Dr. Thomas Tribius, Martin Mildner

Hei everyone,

I’ve been trying to make qt-ruby working for a GUI framework of mine
for quite a while now but i’m getting segfaults at every step, even when
doing the simplest of things (setting a nil date to a calendar,
sometimes when adding a method to a control, sometimes when changing the
parent of a control…). All those situations are extremely nasty to
debug and for each one I need to write a workaround which can be very
ugly at times.
I was wondering if there was someone in charge of manteinance for the
project: I am more than willing to help fixing the bugs, just I don’t
have the time for learning my way through the codebase from scratch. The
project seems dead to me, I couldn’t find a single “real world”
application using the bindings.

Thanks in advance!

Hei Jan,

thanks a lot for your reply. Sorry, I should have posted more details
about my system:

You’re right: I’ve got qt 4.6.4 on my system (ubuntu 10.04) and my
libqt4-ruby version is 4.4.2. I’ve installed everything using synaptic
so i thought i was safe for that matter and i didn’t check for possible
package issues. Ruby version is 1.8.7 p249.
I’m also very interested in making everything work under windows too: i
followed this
http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Qt4-QtRuby_installer_for_Microsoft_Windows
for installing under windows. I get segfaults under windows too, at the
same points as under linux.

I didn’t try to install the gem via rubygems: should I do that instead?
Is there a statically bind version for windows?

Thanks a lot!


Andrea D.

Sorry, I just replied to an old message and deleted content/subject
(with Evolution). Evolution handles it just fine (i see this topic
correctly threaded) and I never noticed.

On May 21, 2010, at 01:49 , Andrea D. wrote:

I’ve been trying to make qt-ruby working for a GUI framework of mine

next time please start a new mail thread of your own instead of thread
hijacking. many, if not most of us use real mail clients and this screws
up threading.

2010/5/21 timr [email protected]:

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™ 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

Hi Andrea,

yes please use shipped qtruby version which comes with Ubuntu, should
work.
I made gem for windows:

http://rubyforge.org/frs/?group_id=181&release_id=42789

http://rubyforge.org/frs/download.php/69355/qtruby4-2.1.0-x86-mswin32.gem

or do (on windows):

**gem install qtruby4

it includes all needed libraries. Just use ruby 1.8.6 and install the
windows gem.

I also got ubuntu 10.04 and it works very well with package bindings.

Best regards,
Jan

Am 21.05.2010 11:42, schrieb Andrea D.:

followed this
http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Qt4-QtRuby_installer_for_Microsoft_Windows for installing under windows. I get segfaults under windows too, at the same points as under linux.

I didn’t try to install the gem via rubygems: should I do that instead?
Is there a statically bind version for windows?

Thanks a lot!


Jan P.
Otto Group · GroupTechnologyPartner - Dresden (GTP)
Touchpoints& Kunde · FI-IM-TK

GroupTechnologyPartner - Dresden GmbH · Freiberger Straße 35 · 01067
Dresden
Telefon +49 (0) 351 497 23 202 · Fax +49 (0) 351 497 23 119

[email protected] · www.ottogroup.com


AG Dresden, HRB 2475
Geschäftsführer: Dr. Thomas Tribius, Martin Mildner

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 K.

Hei Jan,

    I am using the version that comes with ubuntu - that's why I

didn’t
really bother about versions. I will try to install the gem via rubygems
for windows.

I tried again, removing and reinstalling the packages with synaptic, and
I still get the same segfaults. It is hard for me to provide you with
exact examples that cause the issue, since I myself do not understand
what exactly causes them and the code that generates the segfaults is
built over the GUI framework. A very simple one would be to create a
Qt::CalendarWidget and sending selectedDate=, nil to it, like this:

require ‘rubygems’
require ‘Qt4’

app = Qt::Application.new([])
hello = Qt::CalendarWidget.new()
hello.resize(200,200)
hello.show()
hello.selectedDate = nil #[BUG] Segmentation fault ruby 1.8.7
(2010-01-10 patchlevel 249) [i486-linux]

Again, this is just a trivial example and it’s very easy to write a
workaround for it: more nasty stuff happens when trying to add/remove
items for a ListWidget for example. I will try to build a test case for
that too.


Andrea D.

On Fri, 2010-05-21 at 12:33 +0200, Jan P. wrote:

Hi Andrea,

yes please use shipped qtruby version which comes with Ubuntu, should
work.
I made gem for windows:

http://rubyforge.org/frs/?group_id=181&release_id=42789

http://rubyforge.org/frs/download.php/69355/qtruby4-2.1.0-x86-mswin32.gem

I also got ubuntu 10.04 and it works very well with package bindings.

thanks a lot for your reply. Sorry, I should have posted more

details

about my system:

You’re right: I’ve got qt 4.6.4 on my system (ubuntu 10.04) and my
libqt4-ruby version is 4.4.2. I’ve installed everything using
synaptic
so i thought i was safe for that matter and i didn’t check for
possible
package issues. Ruby version is 1.8.7 p249.
I’m also very interested in making everything work under windows
too: i
followed this

http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Qt4-QtRuby_installer_for_Microsoft_Windows
for installing under windows. I get segfaults under windows too, at the
same points as under linux.

I didn’t try to install the gem via rubygems: should I do that
instead?
Jan P.
Otto Group · GroupTechnologyPartner - Dresden (GTP)
Touchpoints & Kunde · FI-IM-TK

GroupTechnologyPartner - Dresden GmbH · Freiberger Straße 35 · 01067
Dresden