What is the garbage collector in Java? -


i new java , confused garbage collector in java. , when comes action. please describe of properties of garbage collector in java.

the garbage collector program runs on java virtual machine gets rid of objects not being used java application anymore. form of automatic memory management.

when typical java application running, creating new objects, such strings , files, after time, objects not used anymore. example, take @ following code:

for (file f : files) {     string s = f.getname(); } 

in above code, string s being created on each iteration of for loop. means in every iteration, little bit of memory being allocated make string object.

going code, can see once single iteration executed, in next iteration, string object created in previous iteration not being used anymore -- object considered "garbage".

eventually, we'll start getting lot of garbage, , memory used objects aren't being used anymore. if keeps going on, java virtual machine run out of space make new objects.

that's garbage collector steps in.

the garbage collector objects aren't being used anymore, , gets rid of them, freeing memory other new objects can use piece of memory.

in java, memory management taken care of garbage collector, in other languages such c, 1 needs perform memory management on own using functions such malloc , free. memory management 1 of things easy make mistakes, can lead called memory leaks -- places memory not reclaimed when not in use anymore.

automatic memory management schemes garbage collection makes programmer not have worry memory management issues, or can focus more on developing applications need develop.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -