Object IDs

A couple of quick questions:

a) Are object id’s ever reused within the life of a Ruby process?

b) Are object id’s unique across the whole Ruby process, or only within
a given context?

Hi,

In message “Re: Object IDs”
on Tue, 11 Jul 2006 23:10:15 +0900, Alex Y.
[email protected] writes:

|a) Are object id’s ever reused within the life of a Ruby process?

They are recycled by garbage collector.

|b) Are object id’s unique across the whole Ruby process, or only within
|a given context?

They are unique in the certain point of the execution.

						matz.

Le 11 juil. 06, à 10:10, Alex Y. a écrit :

A couple of quick questions:

a) Are object id’s ever reused within the life of a Ruby process?

I believe that Object#equal? compares ids if not overridden.

b) Are object id’s unique across the whole Ruby process, or only
within a given context?

Unique across the process.

Guillaume.

Yukihiro M. wrote:

Hi,

In message “Re: Object IDs”
on Tue, 11 Jul 2006 23:10:15 +0900, Alex Y. [email protected] writes:

|a) Are object id’s ever reused within the life of a Ruby process?

They are recycled by garbage collector.
Thanks… That explains a minor oddness I’m seeing. Are they recycled
before the finalizers are called?

|b) Are object id’s unique across the whole Ruby process, or only within
|a given context?

They are unique in the certain point of the execution.
I thought they would be, just wanted to be sure :slight_smile:

Thanks,

Hi,

In message “Re: Object IDs”
on Tue, 11 Jul 2006 23:41:11 +0900, Alex Y.
[email protected] writes:

|Thanks… That explains a minor oddness I’m seeing. Are they recycled
|before the finalizers are called?

No. Finalizers are called before the recycling.

						matz.

On Tue, 11 Jul 2006, Guillaume M. wrote:

b) Are object id’s unique across the whole Ruby process, or only within a
given context?

Unique across the process.

if you wait long enough they can be recycled so i wouldn’t say they are
unique
‘across’ a process. that is to say ruby code which does this

hash = Hash.new{|h, object_id| h[object_id] << 42}

will stack info about two different objects if it runs long enough or is
simply unlucky and only runs for a short time.

in otherwords

id = object.object_id

time

value = ObjectSpace::_id2ref id

may or may not retreive the same object and the error may or may not go
unnoticed.

in summary, i’d say that object_ids are unique in a given context, that
context being an instant of time in a given process. as time
progresses, even
by a millisecond, the chances of objects being recycled increases. fyi.

regards.

-a

Yukihiro M. wrote:

  					matz.

Great. Thanks for confirming that.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs