'Why does removing a reference to resource in java does not lead to garbage collection [duplicate]

FileInputStream fis = new FileInputStream("test.txt");
fis.readAllBytes();

why does fis = null does not make this stream object ready for garbage collection why does it lead to memory leak why do we have to close the stream object



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source