• Post Reply Bookmark Topic Watch Topic
  • New Topic

nested objects  RSS feed

 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello. If anybody has a minute, if I initialized a buffered reader like this...

BufferedReader rd = new BufferedReader(new FileReader(file));

and called

rd.close();

does the rd.close() still leave the FileReader stream out there...potentially causing memory problems if the code runs in many iterations? thank you.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tom,

By convention, close() does the right thing -- i.e., it calls close() on any "nested" streams. All the input and output streams (as well as readers and writers) that are part of the Java standard library behave this way.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if they don't they're broken, because FilterInputStream etc all mention that subclasses must close the underlying stream etc as well.
 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!