0
Is leaked memory freed up when a program exits?
So, I was learning scanners in java and vs code shows a warning that u forgot to close scanners. I searched it on google and came to know that it prevents memory leaks. So, Ive been searching this for whole day and have not got this answer... So, 1. What is a memory leak? 2. Does it affect our main system? 3. Does OS freed up memory leaks after program exit? 4. Can I run java freely in my pc without any worries of memory leaks? 5. Is it necessary to close scanners at the end of the programs? Thank You...
1 Respuesta
+ 2
Memory leak is an area which is allocated by Program as a refference for an object but lost its refference to access so that it is still marked as in use, not freed still..
Main OS frees all refference when Program exits.. Java is mature enough to free memory when no more use by its automatic garbage collocter.. But incorrect resource handling will cause that program crash...
It's good practice to close all unnecessary resources if no more use, even in the middle also..
Edit:
https://stackoverflow.com/questions/15467298/how-far-can-memory-leaks-go