What is a Resource leak in  Scanner Class of java?

What is a Resource leak in Scanner Class of java?


What is a Resource leak in Scanner Class of java?

What is a ‘resource leak’ in Scanner Class of JAVA?

This video aims to educate the viewers on resource leak errors in Scanner class of JAVA.

The code editor used in this video is VS Code.

References and citations have also been from stackoverflow.com
A word of note:

I make these videos with bare-bone resources yetoptimum research. Work is done to make sure the most correct, up-to-date and knowledgeably significant information is provided.
All the content on this channel is non-profit and aimed only for educative purposes. I seek no return for these and derive satisfaction with the time spent in research upon them. Hope you find them worth your time too.
Feedback, opinions and suggestions for topics to cover are welcome.
Cheers!

Connect and know more:

Mail: [email protected]
https://www.github.com/imteshalkarim
https://www.linkedin.com/in/imteshalk
https://www.instagram.com/atomicsage
https://www.twitter.com/imteshal_karim

#java


Content

1.73 -> Hi there, today I shall be discussing on What is a 'resource leak' in Scanner Class
7.42 -> of JAVA?
9.12 -> In java, Scanner class reads inputs from the user in a way that no external classes or
15.35 -> libraries are required.
17.39 -> Whenever, the user invokes a method to accept an integer, string or whatsoever from new
25.029 -> Scanner(System.in); a memory stream stays active in their computer or in other words
32.11 -> a part of that computer's memory stays dedicated to read inputs from the user even when the
38.76 -> program has finished its execution.
42.18 -> As you may see in this background example, upon calling sc.nextInt(); to read an input
49.09 -> from the user, my VS Code throws up a warning flag stating that there has been a resource
55.1 -> leak.
56.1 -> Thus, 'resource leak' implies that some system resource (usually memory) is being lost or
62.42 -> wasted needlessly.
64.559 -> Usually this will impact you when you start getting OutOfMemoryErrors thrown during the
69.85 -> normal operation of your program.
72.89 -> In order to shut down this unnecessary wastage a method .close(); is utilized as in sc.close();
81.64 -> if my scanner object is sc.
84.49 -> However, sc.close(); must ideally be placed at the end of your code only after all methods/objects
93.13 -> depending on inputs from the user have completed their run.
97.23 -> Next, if you will see, adding an sc.close(); option to the very same program fixes the
104.55 -> memory loophole.
106.69 -> All in all, sc.close(); makes your program a tidy bit more efficient even if not adding
113.1 -> it won't make your program unexecutable.
117.35 -> And this was all on today's topic.
120.11 -> All references and citaions are in the description of this video.
123.86 -> I will see you all in a new one.

Source: https://www.youtube.com/watch?v=gKtg5onEiG4