java - FileInputStream and closing -
in code, wherever fileinputstream required argument, i'm doing this:
new obj(new fileinputstream(filelocation)); as not assigning fileinputstream reference variable, not closing using close() method.
does result in memory leaks?
aren't resources released fileinputstream in above approach?
if there no references input stream, garbage collected , stream automatically closed - see fileinputstream.finalize() method. however, not programming practice because not know when garbage collection happen. result in memory leak.
correct , safer approach use try resources block, or in older java versions try-catch-finally, close stream in block - ioutils apache commons, not have care ioexception thrown close() method
Comments
Post a Comment