arun8
arun8

Reputation: 1211

What happens to an Output Stream/Input Stream object reference after calling close method?

When you call close() method on an object reference for OutputStream/InputStream object, will the object reference be pointing to null? or Do we need to explicitly set it to null to make the object memory available for GC?

Upvotes: 0

Views: 403

Answers (2)

ZhongYu
ZhongYu

Reputation: 19702

No. close() will free some underlying resources and objects, but this object still exists.

Actually, close() may not do anything, for example, in ByteArrayInputStream

/**
 * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
 * this class can be called after the stream has been closed without
 * generating an <tt>IOException</tt>.
 */
public void close() throws IOException {
}

you can call close() on it, and then still use it like nothing happens.

Upvotes: 1

Nagendra Putti
Nagendra Putti

Reputation: 3

There is no need to nullify stream, once stream is closed and goes out of scope, the stream is marked for Garbage collection automatically.

Upvotes: 0

Related Questions