[#4595] New block syntax — Daniel Amelang <daniel.amelang@...>

I'm really sorry if this isn't the place to talk about this. I've

25 messages 2005/03/21
[#4606] Re: New block syntax — "David A. Black" <dblack@...> 2005/03/21

Hi --

[#4629] Re: New block syntax — "Sean E. Russell" <ser@...> 2005/03/30

On Monday 21 March 2005 16:17, David A. Black wrote:

[#4648] about REXML::Encoding — speakillof <speakillof@...>

Hi.

15 messages 2005/03/31
[#4659] Re: about REXML::Encoding — "Sean E. Russell" <ser@...> 2005/04/04

On Thursday 31 March 2005 09:44, speakillof wrote:

Is there something wrong with the GC?

From: "Wim van den Bos" <home@...>
Date: 2005-03-28 18:02:46 UTC
List: ruby-core #4626
I tried the following script:


#====================
class Example
end

a=Example.new
ObjectSpace.each_object(Example) { |e| print e,"\n" }
a=nil
GC.enable
GC.start
ObjectSpace.each_object(Example) { |e| print e,"\n" }
#====================
Output:
#<Example:0x2a66e68>
#<Example:0x2a66e68>

The Example object is still active after the GC.start, I expected it to be gone. :-(

So I tried the WeakRef, and this also did something strange.

I wrote the 'Programming Ruby' book example:

#====================
require "weakref"

ref = "fol de rol"
puts "Initial object is #{ref}"
ref = WeakRef.new(ref)
puts "Weak reference is #{ref}"
ObjectSpace.garbage_collect
begin
  puts "But then it is #{ref}"
rescue Exception=>e
  puts e
end
#====================
Output:
Initial object is fol de rol
Weak reference is fol de rol
Illegal Reference - probably recycled

And this worked ok. 
I then copied the whole and just defined a class in between:

#====================
require "weakref"

ref = "fol de rol"
puts "Initial object is #{ref}"
ref = WeakRef.new(ref)
puts "Weak reference is #{ref}"
ObjectSpace.garbage_collect
begin
  puts "But then it is #{ref}"
rescue Exception=>e
  puts e
end
#
# doing it for the second time, and created a class definition
# and now it doesn't work
#
class Example
end
#
ref = "fol de rol"
puts "Initial object is #{ref}"
ref = WeakRef.new(ref)
puts "Weak reference is #{ref}"
ObjectSpace.garbage_collect
begin
  puts "But then it is #{ref}"
rescue Exception=>e
  puts e
end
#====================
Output:

Initial object is fol de rol
Weak reference is fol de rol
Illegal Reference - probably recycled
Initial object is fol de rol
Weak reference is fol de rol
But then it is fol de rol

And this is strange the second 'ref' is not collected. If the class definition is removed all works well.

I tested this in the mswin32 version. 1.8.2 and in the older version 1.6.8 both with the same results.
The cygwin version 1.8.2 had the same results also.

To be sure I the downloaded 1.9.0 and this also went wrong.

It looks like the Garbage Collector is not working properly. Can anybody help.

Thanks.
Wim...


In This Thread

Prev Next