Why we should I close a java.util.Scanner variable?
java
Solution
Resource leak is generally an erroneous pattern of resource consumption where a program does not release the resource it has acquired. This can lead to poor services.
Garbage collection can only manage memory, not other system resources. If your Java program has plenty of free memory, garbage collection will not be triggered automatically.
All OSes have limits on the number of sockets, file handles, etc., that can be open. Thus, the unintentional maintenence of references to non-memory resources can lead to a resource leak. So it is extremely important to manage non-memory resources.
Classes which utilize non-memory resources should provide ways to explicitly allocate/deallocate those resources. We need to explictly call `close()` methods for deallocation of file descriptors in `finally{}`, as it will execute whether or not an exception is thrown.
Problem
I got a warning in Eclipse with the following code: Code: ``` Scanner money = new Scanner(System.in); System.out.println(money.nextLine()); //money.close(); ``` Warning: ``` Description Resource Path Location Type Resource leak: 'money' is never closed apples.java /SwordsNMoney/src line 6 Java P ``` What is this warning and what does 'Resource Leak' mean? Thank you.