[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

GC retentive? or "I'm not putting out the garbage!"

rickhg12hs

4/14/2006 7:47:00 AM

I don't understand some things about the garbage collector ... but I'd
like to.

$ ruby -w -e 'puts "Uncollected Bignums: %d" %
ObjectSpace.each_object(Bignum) {|i| p i}'
Uncollected Bignums: 0

Okay good - no Bignums hanging out.

$ ruby -w -e 'GC.start;puts "Uncollected Bignums: %d" %
ObjectSpace.each_object(Bignum) {|i| p i}'
Uncollected Bignums: 0

This is good too. GC doesn't instantiate Bignums.

$ ruby -w -e 'Integer("8"*50);puts "Uncollected Bignums: %d" %
ObjectSpace.each_object(Bignum) {|i| p i}'
88888888888888888888888888888888888888888888888888
Uncollected Bignums: 1

This seems reasonable - Bignum created and it shows up in ObjectSpace.

$ ruby -w -e 'a=Integer("8"*50);puts "Uncollected Bignums: %d" %
ObjectSpace.each_object(Bignum) {|i| p i}'
88888888888888888888888888888888888888888888888888
Uncollected Bignums: 1

This really makes sense - "a" needs to point to the Bignum.

$ ruby -w -e 'a=Integer("8"*50);GC.start;puts "Uncollected Bignums: %d"
% ObjectSpace.each_object(Bignum) {|i| p i}'
88888888888888888888888888888888888888888888888888
Uncollected Bignums: 1

Makes sense - can't throw away Bignum that "a" is referencing.

$ ruby -w -e 'Integer("8"*50);GC.start;puts "Uncollected Bignums: %d" %
ObjectSpace.each_object(Bignum) {|i| p i}'
88888888888888888888888888888888888888888888888888
Uncollected Bignums: 1

Hmmmm. Why is the Bignum still here?

$ ruby -w -e 'a=Integer("8"*50);a=nil;GC.start;puts "Uncollected
Bignums: %d" % ObjectSpace.each_object(Bignum) {|i| p i}'
88888888888888888888888888888888888888888888888888
Uncollected Bignums: 1

Same here. Why wasn't the Bignum garbage collected?

5 Answers

ts

4/14/2006 7:56:00 AM

0

>>>>> "r" == rickhg12hs <rickhg12hs@gmail.com> writes:

r> $ ruby -w -e 'Integer("8"*50);GC.start;puts "Uncollected Bignums: %d" %
r> ObjectSpace.each_object(Bignum) {|i| p i}'
r> 88888888888888888888888888888888888888888888888888
r> Uncollected Bignums: 1

r> Hmmmm. Why is the Bignum still here?

The GC is conservative : it has found, somewhere on the stack, a reference
to the Bignum. This is why it don't remove it.


--

Guy Decoux

Gene Tani

4/14/2006 1:21:00 PM

0


ts wrote:
> >>>>> "r" == rickhg12hs <rickhg12hs@gmail.com> writes:
>
> The GC is conservative : it has found, somewhere on the stack, a reference
> to the Bignum. This is why it don't remove it.
>
>
> --
>
> Guy Decoux

discussion re:reachability_paths
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/c9530bf2d5d8...

rickhg12hs

4/14/2006 8:46:00 PM

0

Thanks for the replies.

I had searched the group threads for GC related posts buts there are so
many of them I couldn't find what I was looking for. Is there a GC FAQ
somewhere with all the info consolidated?

Gene Tani

4/14/2006 11:32:00 PM

0


rickhg12hs wrote:
> Thanks for the replies.
>
> I had searched the group threads for GC related posts buts there are so
> many of them I couldn't find what I was looking for. Is there a GC FAQ
> somewhere with all the info consolidated?

http://whytheluckystiff.net/articles/theFullyUpturn...

http://www.rubygarden.org/ruby?GCAndMemory...

Found here:
http://del.icio.us/t...

rickhg12hs

4/15/2006 5:32:00 AM

0

Awesome, thanks!