# Something's wrong with ObjectSpace

**URL:** <https://www.ruby-forum.com/t/somethings-wrong-with-objectspace/177863>\
**Category:** IronRuby\
**Created:** [October 25, 2009, 9:26pm UTC](https://www.ruby-forum.com/t/somethings-wrong-with-objectspace/177863 "2009-10-25T21:26:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [October 25, 2009, 9:26pm UTC](https://www.ruby-forum.com/t/somethings-wrong-with-objectspace/177863/1 "2009-10-25T21:26:18Z")

</div>

Hey,

The next REPL session works fine in MRI but in IR it throws an error:

> > > str = “sss”  
> > > =\> “sss”
> 
> > > ObjectSpace.each\_object(String) { |x| puts x }  
> > > d:\IronRuby\GitRepository2\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA\_RESTRICTED\Builtins\ObjectSpace.cs:37:in  
> > > `each\_object’: each\_object only supported for objects of type Class or  
> > > Module (RuntimeError)  
> > > from :0

I looked a bit into it and IR identifies String as a descendant of  
Object and not Module as it expects. This problem makes it impossible  
to run each\_object on Numeric as well (and I guess more types that are  
mapped directly to CLR types).

Should I create a bug?

## Thanks! Shay.

---

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [October 26, 2009, 12:01am UTC](https://www.ruby-forum.com/t/somethings-wrong-with-objectspace/177863/2 "2009-10-26T00:01:24Z")

</div>

This is by design. We don’t support enumerating objects that are not  
modules. A string instance is not a module.  
Why do you need to enumerate all allocated strings?

Tomas

---

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [October 26, 2009, 6:24am UTC](https://www.ruby-forum.com/t/somethings-wrong-with-objectspace/177863/3 "2009-10-26T06:24:44Z")

</div>

I don’t have a specific need for that right now. However, it does sound  
logical to me that you’d want to get all the strings in your  
application. It  
becomes even more reasonable when you run each\_object with Thread, to  
find  
out all defined. This doesn’t work as well.

But, this is not the most used class out there so I IronRuby will  
continue  
to ROCK despite that.

Thanks for the reply Tomas,  
Shay.

On Mon, Oct 26, 2009 at 1:00 AM, Tomas M. \<

---

<div class="post-metadata">

**Author:** ![shayfriedman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@shayfriedman](https://www.ruby-forum.com/u/shayfriedman)\
**Post date:** [October 26, 2009, 7:08am UTC](https://www.ruby-forum.com/t/somethings-wrong-with-objectspace/177863/4 "2009-10-26T07:08:38Z")

</div>

Such feature would incur a significant performance hit to all  
applications. If you really need to get all instances of some class you  
can e.g. monkey-patch its initialize method and store the instances in a  
(weak) list. Although we could provide a command line option that would  
allow us to match MRI’s semantics of each\_object precisely, I don’t see  
a strong use case for such feature. All use cases I have seen so far  
could be implemented in much more efficient way that doesn’t rely on  
ObjectSpace.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Shay F.  
Sent: Sunday, October 25, 2009 10:10 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Something’s wrong with ObjectSpace

I don’t have a specific need for that right now. However, it does sound  
logical to me that you’d want to get all the strings in your  
application. It becomes even more reasonable when you run each\_object  
with Thread, to find out all defined. This doesn’t work as well.

But, this is not the most used class out there so I IronRuby will  
continue to ROCK despite that.

Thanks for the reply Tomas,  
Shay.  
On Mon, Oct 26, 2009 at 1:00 AM, Tomas M.  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:  
This is by design. We don’t support enumerating objects that are not  
modules. A string instance is not a module.  
Why do you need to enumerate all allocated strings?

Tomas
