Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.ruby

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2010, 06:30 AM
timr
Guest
 
Posts: n/a
Default 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:ependency=>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?
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 05-21-2010, 08:13 AM
Josh Cheek
Guest
 
Posts: n/a
Default Re: OMG, why are there so many Strings in ObjectSpace!

[Note: parts of this message were removed to make it a legal post.]

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]
> = ObjectSpace.each_object(cla).to_a.length}
> hash
>
> {Tiger=>1, Gem::SourceIndex=>1, Gem::Version=>601, String=>57656,
> RubyToken::TkNL=>1, Gem:ependency=>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?
>
>

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

Reply With Quote
  #3 (permalink)  
Old 05-21-2010, 08:36 AM
Robert Dober
Guest
 
Posts: n/a
Default Re: OMG, why are there so many Strings in ObjectSpace!

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.

Reply With Quote
  #4 (permalink)  
Old 05-21-2010, 08:39 AM
Robert Dober
Guest
 
Posts: n/a
Default Re: OMG, why are there so many Strings in ObjectSpace!

> 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

Reply With Quote
  #5 (permalink)  
Old 05-21-2010, 08:46 AM
Robert Dober
Guest
 
Posts: n/a
Default Re: OMG, why are there so many Strings in ObjectSpace!

On Fri, May 21, 2010 at 8:35 AM, timr <timrandg@gmail.com> 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.
>
>




--
The best way to predict the future is to invent it.
-- Alan Kay

Reply With Quote
  #6 (permalink)  
Old 05-21-2010, 08:49 AM
Andrea Dallera
Guest
 
Posts: n/a
Default ruby-qt bindings - is somebody in charge of those?

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!


--
Andrea Dallera
http://github.com/bolthar/freightrain
http://usingimho.wordpress.com


Reply With Quote
  #7 (permalink)  
Old 05-21-2010, 09:28 AM
Jan Pilz
Guest
 
Posts: n/a
Default Re: ruby-qt bindings - is somebody in charge of those?

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 Dallera:
> 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!
>
>
>



--
__________________________________________________ ___

Jan Pilz
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

jan.pilz@osp-dd.de · www.ottogroup.com
__________________________________________________ ___

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


Reply With Quote
  #8 (permalink)  
Old 05-21-2010, 09:42 AM
Andrea Dallera
Guest
 
Posts: n/a
Default Re: ruby-qt bindings - is somebody in charge of those?

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...rosoft_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 Dallera
http://github.com/bolthar/freightrain
http://usingimho.wordpress.com


On Fri, 2010-05-21 at 18:28 +0900, Jan Pilz wrote:
> 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 Dallera:
> > 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!
> >
> >
> >

>
>




Reply With Quote
  #9 (permalink)  
Old 05-21-2010, 09:42 AM
Ryan Davis
Guest
 
Posts: n/a
Default Re: ruby-qt bindings - is somebody in charge of those?


On May 21, 2010, at 01:49 , Andrea Dallera 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.


Reply With Quote
  #10 (permalink)  
Old 05-21-2010, 09:46 AM
Andrea Dallera
Guest
 
Posts: n/a
Default Re: ruby-qt bindings - is somebody in charge of those?

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 Fri, 2010-05-21 at 18:42 +0900, Ryan Davis wrote:
> On May 21, 2010, at 01:49 , Andrea Dallera 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.
>
>
>




Reply With Quote
  #11 (permalink)  
Old 05-21-2010, 09:51 AM
Robert Klemme
Guest
 
Posts: n/a
Default Re: OMG, why are there so many Strings in ObjectSpace!

2010/5/21 timr <timrandg@gmail.com>:
> 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/

Reply With Quote
  #12 (permalink)  
Old 05-21-2010, 10:34 AM
Jan Pilz
Guest
 
Posts: n/a
Default Re: ruby-qt bindings - is somebody in charge of those?

[Note: parts of this message were removed to make it a legal post.]

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.ph...86-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 Dallera:
> 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...rosoft_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 Pilz
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

jan.pilz@osp-dd.de · www.ottogroup.com
__________________________________________________ ___

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


Reply With Quote
  #13 (permalink)  
Old 05-21-2010, 10:56 AM
Andrea Dallera
Guest
 
Posts: n/a
Default Re: ruby-qt bindings - is somebody in charge of those?

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 Dallera
http://github.com/bolthar/freightrain
http://usingimho.wordpress.com



On Fri, 2010-05-21 at 12:33 +0200, Jan Pilz 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.ph...86-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 Dallera:
> > 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...rosoft_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 Pilz
> 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
>
> jan.pilz@osp-dd.de · www.ottogroup.com
> __________________________________________________ ___
>
> AG Dresden, HRB 2475
> Geschäftsführer: Dr. Thomas Tribius, Martin Mildner



Reply With Quote
  #14 (permalink)  
Old 05-25-2010, 06:59 PM
Charles Oliver Nutter
Guest
 
Posts: n/a
Default Re: OMG, why are there so many Strings in ObjectSpace!

JRuby master for your little script with ObjectSpace on:

~/projects/jruby =E2=9E=94 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@googlemail.com> wrote:
> 11:47:36 Temp$ cat c.rb
> cnt =3D Hash.new 0
>
> ObjectSpace.each_object(Object) do |o|
> =C2=A0cnt[o.class] +=3D 1
> end
>
> cnt.sort_by {|k,v| -v}.each do |cl,count|
> =C2=A0printf "%6d %s\n", count, cl
> end


Reply With Quote
 
Reply

Popular Tags in the Forum
objectspace, omg, strings

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: matching strings in a large set of strings Mark Tolonen Newsgroup comp.lang.python 0 04-29-2010 11:00 AM
Re: popen - reading strings - constructing a list from the strings MRAB Newsgroup comp.lang.python 0 05-20-2009 03:35 PM
Re: find and replace strings nospam@HOWLES.COM (Howard Schreier Newsgroup comp.soft-sys.sas 0 01-10-2007 01:25 AM
Re: find and replace strings Yu Zhang Newsgroup comp.soft-sys.sas 0 01-08-2007 04:33 PM
find and replace strings Arjen Newsgroup comp.soft-sys.sas 0 01-08-2007 03:46 PM



All times are GMT. The time now is 02:29 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.