From: Mat Schaffer Date: 2006-06-06T22:53:37+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. No expert here, and I'm sure it depends on the OS. But I think the biggest danger you face is loosing some of the data you wrote to the file. It's possible that some data is in a buffer and hasn't actually been written when the program exits. Closing a file writes the buffer, so not closing it and just exiting may leave buffer data unwritten. -Mat