What is the disadvantage of garbage collector?- Although garbage collector runs in its own thread, still it has impact on performance.
- It adds overheads since JVM has to keep constant track of the object which are not referenced and then free these unreferenced objects.
- Garbage collector can be force to run using "System.gc" or "Runtime.gc".
- They consume the computing resources in deciding as to which memory to free and even if the developer knows this.
- The explicit freeing of objects is that garbage collection gives programmers less control over the scheduling of CPU time devoted to reclaiming memory.
- It is impossible to predict when a garbage collector will be invoked and how long it will take to run.
- Garbage collectors stop the entire program while seeking and collecting garbage objects, they can cause arbitrarily long pauses at arbitrary times during the execution of the program.
- Such garbage collection pauses can sometimes be long enough to be noticed by users.
- These pauses prevent the programs from responding to events quickly enough to satisfy the requirements of real-time systems.
- If a garbage collection algorithm is capable of generating pauses lengthy enough to be either noticeable to the user or make the program unsuitable for real-time environments, the algorithm is said to be disruptive.
- To minimize the potential disadvantages of garbage collection compared to the explicit freeing of objects, a common design goal for garbage collection algorithms is to minimize or, if possible, eliminate their disruptive nature.