What happens to a BufferedReader that doesn't get closed within a callable.call?

后端 未结 5 744
后悔当初
后悔当初 2021-02-04 14:47

I have three questions.

To explain, I was reviewing someone\'s code, and noticed BufferedReaders sometimes aren\'t being closed. Usually, Eclipse gives a w

5条回答
  •  暖寄归人
    2021-02-04 15:24

    BuffereddReader close()

    Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

    So, if you don't close(), system resources may be still associated with the reader which may cause memory leak.

    Why eclipse not highlighting: it is not compile time error if you ignore calling close(), so eclipse don't highlight.

提交回复
热议问题