+ 2

what is garbage collection in the context of java?

25th Nov 2018, 5:29 AM
SACHIN PAGARE
SACHIN PAGARE - avatar
2 odpowiedzi
+ 2
When you initialize an object, it gets created on the heap (dynamic memory). Now usually you have a variable or an array referencing this object. However, if you don't - maybe you assigned your variable a different object or you removed the object from the array - the object will still exist in the memory, but you can't access it anymore. That's called a memory leak. Java remembers all memory segments it uses and regularly deletes all data that's not referenced anymore in order to free memory. That's called garbage collection.
26th Nov 2018, 4:26 AM
Chris
Chris - avatar
+ 1
I guess, it is deleteting unused objects and pointers
25th Nov 2018, 6:22 AM
Idris Tuna