title: Why is it necessary to close a file after using it?
body: <p>I read a question from a book that said "If the OS closes a file after the program terminates, why does the programmer need to close a file manually (i.e. call <code>file.close()</code>)?"</p>
  
  <p>The only reason I could come up with is that the program may not terminate correctly, and so the file may be still open, therefore consuming system resources, because the file is kept on a buffer.</p>
  
  <p>Are there any other reasons?</p>
  
  <p>EDIT: I thought of another reason. Calling <code>file.close()</code> obliges the OS to flush to disk any changes that haven't been committed to the file.</p>