From: Logan Capaldo Date: 2006-06-06T22:58:25+09:00 Subject: Re: leaving files open On Jun 6, 2006, at 9:45 AM, Dirk Meijer wrote: > hello list! > i've learnt to open files like this: > > File.open("foo", "w") do |file| > file.write "foo" > end > > because everyone always says it's _dangerous_ to leave files open... > just, wondering, what could really happen? > > suppose i write a program that write to a file, infinitely, i'll > want to > shut this program off after a while, the file will not properly > close... > what could actually happen? > > greetings, Dirk. The major issue with not closing files on *Nix is that you *could* run out of file descriptors for that process. The OS will close the file at program termination, but you can and should use hooks like at_exit{} and END {} to make sure (If you need to keep one file open indefinitely). STDOUT for instance is a file, you don't see most people closing that.