Threads & GC

Hello,

I’m really confused by the behaviour of the following code:

irb(main):038:0> Thread.start do
irb(main):039:1* Mysql.connect(‘localhost’, ‘test’, ‘’, ‘test’)
irb(main):040:1> end
=> #<Thread:0x401de1f4 dead>
irb(main):041:0> ObjectSpace.each_object(Mysql) do |o| puts o.id end
537850026
=> 1
irb(main):042:0> GC.start
=> nil
irb(main):043:0> ObjectSpace.each_object(Mysql) do |o| puts o.id end
537850026
=> 1

Why does the Mysql object still exist after GC.start?

Andreas

irb(main):042:0> GC.start

              ^^
              >>

Why does the Mysql object still exist after GC.start?

because GC::start is run on line 42, and ruby don't like this

p.s.: :-)))))

Guy Decoux

“ts” decoux@moulon.inra.fr schrieb im Newsbeitrag
news:200401191641.i0JGfox15401@moulon.inra.fr

irb(main):042:0> GC.start
^^

Why does the Mysql object still exist after GC.start?

because GC::start is run on line 42, and ruby don’t like this

p.s.: :-)))))

Dang! And I thought it was because Matz never singned a written treaty
that CG.start will collect all unemployed instances…

:slight_smile:

robert