JAVA questions
Local variables are never garbage collected.
True False
ANSWER
FALSE
EXPLANATION
IN MOST OF THE TIMES GARBAGE COLLECTION FOR THE LOCAL VARIABLES ARE NOT NEEDED, AS THEY ARE DESTROYED AUTOMATICALLY AFTER THE FUNCTION OR METHOD IS EXECUTED.
NOTE:- ONLY FOR THE CASES OF OBJECTS, GARBAGE COLLECTION IS NEEDED, AS THEY ARE STORED IN HEAP.
(EXCEPTION)
IN SOME CASES, LIKE IF YOU CHANGE VALUE OF YOUR VARIABLE TO NULL IN METHOD. THEN THE REFERENCE TO PREVIOUS VALUE OF THAT VARIABLE IS LOST BY THE VARIABLE AND THERE IS NO WAY TO RECLAIM THAT VALUE AS ITS REFERENCE IS LOST. SO, IN THAT CASE LOCAL VARIABLES ARE GARBAGE COLLECTED.
##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####
Get Answers For Free
Most questions answered within 1 hours.