GC Not Cleaning Up (was: Tempfile is not automatically removed, Ruby)

instances of Ruby tempfile automatically delete their corresponding file when releasing links. However, I have one machine on which it is not. Code

irb> require 'tempfile'
=> true
irb> t = Tempfile.new('test32')
=> #<File:/tmp/test32.27778.0>
irb> exit

on all my test machines, this removes test32 except one. I tried deleting the file with File.deleteand unfortunately this works fine. Is there some kind of ruby ​​configuration I'm missing?

Ruby version

ruby 1.8.6 (2009-06-08 patchlevel 369) [i686-linux].

Edit: Some additional information that appeared in a conversation with DigitalRoss: if I explicitly release the Tempfile link (t = nil), then Tempfile will be cleared. Is it possible that the GC has been fixed or modified in some way so that it is needed?

, "" , "" .

include ObjectSpace
t = "blah"
define_finalizer(t, proc {|id| print "yes finalized id=#{id}", "\n" })

"yes finalized" , t nil.

+3
2

, ...

Ruby, , Tempfile, . ( , , Kernel:: at_exit, .) , - GC . . , Tempfile, GC .

ross@deb:~$ irb
>> require 'tempfile'
=> true
>> $DEBUG=true
=> true
>> t=Tempfile.new('aaa')
=> #<File:/tmp/aaa20090905-21437-1d460as-0>
>> GC.start
=> nil
>> t=nil
=> nil
>> GC.start
removing /tmp/aaa20090905-21437-1d460as-0...done
=> nil
>> exit
ross@deb:~$ 
+2

1.8.7 , , 1.8.6.

rails Tempfile . . : http://github.com/jwinky/ruby_tempfile_ioerror

+1

Source: https://habr.com/ru/post/1716988/


All Articles