JDK-4081750 : java.io.RandomAccessFile: Add a finalize method
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.4,1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_95,windows_98
  • CPU: x86
  • Submitted: 1997-09-25
  • Updated: 1998-08-26
  • Resolved: 1998-08-26
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description

Name: diC59631			Date: 09/25/97


I know one isn't supposed to rely on files being
closed by themselves.

But, RandomAccessFile should have a finalize()
method which closes the file descriptor, the same
way that FileOutputStream and friends do.
======================================================================

Comments
WORK AROUND Name: diC59631 Date: 09/25/97 ======================================================================
11-06-2004

EVALUATION As the submitter seems to realize, finalization is not a reliable way to close open files. At best it is a flaky method of last resort that shouldn't be relied upon. Files should be opened within try/finally blocks that take care to ensure that they are closed. Having said that, adding a finalize() method to RandomAccessFile is something to consider for the next feature release. -- mr@eng 10/6/1997 In light of 4099999, I'm not going to do this. Using a finalizer to close an open file is just a bad idea, especially since it closes the underlying FileDescriptor, which may be in use by some other stream. -- mr@eng 1/7/1998 There is yet another reason not to add a finalize() method to RandomAccessFile: It would impose a significant performance penalty upon programs that need to open many files quickly. The File{In,Out}putStream classes, which do have finalizers, are unusable by such programs due to the strain that they place upon the garbage collector. If we add a finalizer to RandomAccessFile then we will adversely affect the performance of existing programs which rely upon the fact that RandomAccessFile has no finalizer. -- ###@###.### 2003/2/11
02-11-0177