0
What is the purpose of garbage collection in java
3 odpowiedzi
+ 2
The garbage collector cleans the memory for you when you don't use a variable anymore. It does that after a fixed time step, say, 5 seconds. If you have a big time step, your app can freeze for some seconds when the garbage collector runs. However, a too small time step slows your app down because it always gets interrupted.
In other languages like C, C++ or Rust, you don't have a garbage collector and you must clean your memory by hand.
+ 2
In a rather simplified illustration, the garbage collector is like a cleaning service agent in your office, other employees leave garbage behind during work hours, papers scattered all over the place, empty markers left on the tables, and of course empty coffee or tea cups.
All these unused resources (garbage) need to be cleaned up to keep the office clean and comfortable for the office works to continue smoothly (imagine working in a dirty office).
The garbage collector "watches" when a resource is no longer in use, and return them to the system, to allow them to be reused later and to reduce unused resources (garbage) from clogging up the system, making it unresponsive due to lack of available resources to use.
Hth, cmiiw
+ 1
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
Read more on:- http://crbtech.in/Java-Training/garbage-collectors-java-types/