Java / Garbage collection
How does Garbage Collection work in Java?
Garbage collection works by employing several GC algorithms, for example, Mark and Sweep.
Garbage Collector is the program running in the background that looks into all the objects in the memory and find out objects that are not referenced by any part of the program. All these unreferenced objects are deleted and space is reclaimed for allocation to other objects.
There are many kinds of garbage collector available in Java to collect different area of heap memory, some of them include serial, parallel and concurrent garbage collectors.
The basic way of garbage collection involves 3 steps:
- Marking is the first step where garbage collector identifies which objects are in use and which ones are not in use.
- Normal Deletion: Garbage Collector removes the unused objects and reclaim the free space to be allocated to other objects.
- Deletion with Compacting: After deleting unused objects, all the survived objects can be moved to be together. This will increase the performance of allocation of memory to newer objects.
Earn bitcoins upto $250 (free), invest in other Cryptocurrencies when you signup with blockfi. Use the referral link: https://blockfi.com/?ref=f2ab78ba
Using BlockFi, don't just buy crypto - start earning on it. Open an interest account with up to 8.6% APY, trade currencies, or borrow money without selling your assets.
Invest now!!! Get Free equity stock (US,UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
More Related questions...