FileReader f = new FileReader("foo.txt");
// Now there is a file descriptor (or file handle) created by OS.
f = null;
// Please note: we don't call f.close(), will the file handle
// be closed automatically?
它会导致Java中的资源(文件描述符/文件句柄)泄漏吗?
答案 0 :(得分:2)
这是重复:Do unclosed streams cause memory leaks in java?
简短的回答是:不是真的。流将由垃圾收集器完成。但是你不知道什么时候会发生这种情况。所以你浪费了一些时间的记忆。