问题描述
这句话是什么,关闭 ByteArrayOutputStream
无效()是什么意思?
What does this statement, "Closing a ByteArrayOutputStream
has no effect" (http://java.sun.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html#close()) mean?
我想确保释放 ByteArrayOutputStream
中的内存。 ByteArrayOutputStream.close()
真的释放内存吗?
I want to make sure the memory in ByteArrayOutputStream
gets released. Does ByteArrayOutputStream.close()
really release the memory?
谢谢。
推荐答案
没有。它什么都没做。您可以查看其源代码:
No. It does absolutely nothing. You can look at its source code:
public void close() throws IOException {
}
要释放内存,请确保没有引用它并让垃圾收集器执行其操作。就像任何其他普通对象一样。
To release the memory, make sure there are no references to it and let the Garbage Collector do its thing. Just like with any other normal object.
基于文件和套接字的流是特殊的,因为它们使用非内存操作系统资源(文件句柄),你可以用完独立的记忆。这就是为什么明确地关闭它们很重要。但这不适用于纯粹基于内存的 ByteArrayOutputStream
。
File- and Socket-based streams are special because they use non-memory OS resources (file handles) that you can run out of independantly of memory. That's why closing them explicitly is important. But this does not apply to the purely memory-based ByteArrayOutputStream
.
这篇关于关闭ByteArrayOutputStream无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!