Impossible to enforce garbage collection

http://pastie.org/1970654

Can anyone tell me why the object created with finializer is not garbage
collected during GC.start executed in line 10 please ?

Robert Pankowecki

On Wed, 25 May 2011 20:11:20 +0900, Robert Pankowecki wrote:

http://pastie.org/1970654

Can anyone tell me why the object created with finializer is not
garbage
collected during GC.start executed in line 10 please ?

Robert Pankowecki

Because exceptions thrown in finalizers are silently ignored:
http://rxr.whitequark.org/mri/source/gc.c#2862
(note the last rb_protect).

But ‘puts 12345’ is executed at the end of the program instead in the
middle of the test.

On Wed, May 25, 2011 at 1:11 PM, Robert Pankowecki
[email protected] wrote:

http://pastie.org/1970654

Can anyone tell me why the object created with finializer is not garbage
collected during GC.start executed in line 10 please ?

There are no guarantees - neither about when GC will occur nor about
which objects it will collect. AFAIK Ruby MRI’s GC doesn’t even
bother to do something until your memory usage goes beyond a
particular point. It’s unlikely that you reach that point with your
test.

Kind regards

robert

Robert Pankowecki wrote in post #1000863:

http://pastie.org/1970654

Can anyone tell me why the object created with finializer is not garbage
collected during GC.start executed in line 10 please ?

The GC puts “objects with finalizers” on a queue to be GC’ed later,
because (I guess) it doesn’t want to run any ruby code during the middle
of the GC run.

-roger-

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