Wednesday, August 24, 2011

Understanding Java Garbage Collection and its algorithms.

Here is a deeper dive into - Understanding Java Garbage Collection and its algorithms.

This article is in continuation to my article on "Understanding Java Heap Space and Memory Tuning". Make sure you understand the concepts behind Java heap usage before diving into garbage collection details.

We cannot force Garbage Collection, but could request it by calling System.gc() or Runtime.gc().

JVM does not guarantee that GC will be started immediately. Also, Garbage collection does not guarantee that a program will not run out of memory.

JVM automatically removes the unused variables/objects from the memory... to create free space for the programs that are currently running.

Garbage Collection runs on Heap and NOT stack

The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected. We usually nullify the object references of large objects like collections, maps etc in the finalize block.

An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.

An object's finalize() method may only be invoked once by the garbage collector.

A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected. The system will not do it and you cannot force it either.

An unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.

GC is a daemon thread that runs in JVM

How does an object become eligible for GC

1. All available object references are null
2. When parent Object references become null, all child objects (objects references in other object) also become eligible for GC
3. Make the reference variable to refer to another object and neither of the objects is referenced by any other object. That's an island of isolation. Basically, an island of isolation is a group of objects that reference each other but they are not referenced by any active object in the application

Various types of Garbage collection Java which can be used by passing params to the JVM via executing a java program.

version of the young generation collector

collect the tenured generation

When GC happens, it may run parallel to the application or can pause the application for times when GC is done.

UseParallelGC : Young Generation is partially and parallel'ly collected. It is a minor collection & carried in parallel to executing code and is not much of a performance impact. When it performs a minor GC, the VM moves any remaining objects from the eden space to one of the survivor spaces. The VM moves objects that live long enough in the survivor spaces to the "tenured" space in the old generation.

UseConcMarkSweepGC : This is a full GC and application pauses while it runs. It is a performance heavy. When the old generation fills up, there is a full GC that is often much slower because it involves all live objects.


  1. Thanks for helping me to understand Garbage Collection and its algorithms concepts. As a beginner in java programming your post help me a lot. java training in chennai

  2. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in TECHNOLOGY , kindly contact us
    MaxMunus Offer World Class Virtual Instructor-led training on TECHNOLOGY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Pratik Shekhar
    Ph:(0) +91 9066268701

  3. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

  4. Established in 2016 is providing top quality domain and hosting services worldwide to
    our valued customers and trying to play a little role in their success.We offer about 500 distinctive gTlds and ccTlds
    to look over which includes old master class gTlds like .com, .net and .org, in addition this we also offer newly launched Tlds
    like .xyz, .online, .master, .office, .on, .top and .club. We can assist you with choosing the best fitting name. Let's bring your
    thought or business on the web. visit this site to know more.

    Do you wanna buy SSD Web Hosting visit here.
    Find best Cheap Web Hosting here.

  5. Ez battery reconditioning reviews - You can now easily revive your old batteries with this
    Ez battery reconditioning pdf which provides step by step instructions for recondition a battery.
    Ez battery reconditioning blog publishes how Ez battery reconditioning programs works
    and where buy Ez battery reconditioning step by step program online after this
    candid Ez battery reconditioning reviews. Battery reconditioning course is newbie friendly. It may help you
    set up and run your own battery reconditioning business by learning this skill at home.
    How to recondition a battery with Ez battery reconditioning .
    Have you heard about Tom Ericson's Ez battery reconditioning reviews technique and
    are wondering whether it is possible or not. visit this site to know more. Thank you every one.

  6. I like you article. if you you want to saw Sufiyana Pyaar Mera Star Bharat Serials Full
    Sufiyana Pyaar Mera

  7. Tech Gadgets reviews and latest Tech and Gadgets news updates, trends, explore the facts, research, and analysis covering the digital world.
    You will see Some Tech reviews below,

    lg bluetooth headset : You will also wish to keep design and assorted features in mind. The most essential part of the design here is the buttonsof lg bluetooth headset .

    Fastest Car in the World : is a lot more than the usual number. Nevertheless, non-enthusiasts and fans alike can’t resist the impulse to brag or estimate according to specifications. Fastest Car in the World click here to know more.

    samsung galaxy gear : Samsung will undoubtedly put a great deal of time and even more cash into courting developers It is looking for partners and will allow developers to try out
    different sensors and software. It is preparing two variants as they launched last year. samsung galaxy gear is very use full click to know more.

    samsung fridge : Samsung plans to supply family-oriented applications like health care programs and digital picture frames along with games It should stick with what they know and they
    do not know how to produce a quality refrigerator that is worth what we paid. samsung fridge is very usefull and nice product. clickcamera best for travel: Nikon D850: Camera It may be costly, but if you’re trying to find the very best camera you can purchase at this time, then Nikon’s gorgeous DX50 DSLR will
    probably mark each box. The packaging is in a vibrant 45.4-megapixel full-frame detector, the picture quality is simply wonderful. However, this is just half the story. Because of a complex 153-point AF system along with a brst rate of 9 frames per minute. camera best specification. click here to know more.

  8. Ultra Fast KetoYour frame desires insulin to save fats, carbohydrates and proteins. The claims of chromium picolinate as a herbal weight reduction supplement is that it can suppress your urge for food and assist your frame burn fats even as constructing muscle groups. Advocates say that it permit you to burn greater energy, too. But, many research have said that chromium picolinate is probably ineffective for losing weight. • conjugated linoleic acid (cla).

  9. Dynamic Keto And what is greater, it's miles very hard to have a specially excessive carbohydrate weight loss program except one's meals is quite a good deal processed. I take a look at so much needless worry and fretting approximately calories, which in my revel in can be averted by using consuming much less carbs. Let us stop fretting and think back to nature and what nature or god supplied for us. To illustrate, allow me ask you a few questions: while became the final time you saw a bread loaf tree? In which do cartons of fruit juice develop?

  10. Diamond Keto Plus Even though managing your sickness may be very difficult, type diabetes is not a situation you should simply live with. You could make easy changes to your every day habitual and decrease each your weight and your blood sugar tiers. Dangle in there, the longer you do it, the less complicated it gets.

  11. Enhanced Keto The better we experience, the more likely we are to need to shed pounds. ) ask human beings to assist. All of us, such as own family, pals, dieticians, psychologists and so on. We recognise what assist we need, and we ought to ask for it. ) don't fad diet. Maximum brief fixes are extraordinarily bad.

  12. Ultra Fast Keto Of course, you pay attention the stories of circle of relatives drama, however it appears to run much deeper than that. It is as if thanksgiving has turn out to be an overeating touch recreation. We start preparing earlier and even begin bemoaning the aftereffects of an excessive amount of meals nicely earlier than the actual occasion. We act as if eating till bursting factor is predicted and completely out of our manipulate. And just like a football sport, thanksgiving comes replete with the aftergame statement and playbyplay.

  13. Ultra Fast Keto Treat your self as a praise, this may assist to maintain you on course and influenced. Healthful treats may be quality. You could reward your self with a experience if you have lost a certain weight. Specially if it is a taking walks trip or includes some shape of exercise.

  14. Ultra Fast Keto and "why is that this critical to me?" when your answers arrive, get them from your mind, via your frame and jot them down. In a e book, on paper, in which ever, simply write them down. Make an extended listing and verbalize your middle solutions as frequently as possible out loud. The more motives you have got and the more engrained they turn out to be into your psyche, the greater core electricity you'll be able to draw on when the hard gets going. And we both recognise that tough instances are a part of the technique of exchange.

  15. ketogenicpedia Do a healthy breakfast. Breakfast like a king. Do not forget about your breakfast by way of just taking a slice and a glass of juice or a cup of tea or espresso. A healthful breakfast energizes you loads and you could paintings successfully all day lengthy. Drink or glass of water before breakfast. Add plenty proteins and carbohydrates to your meals. Furthermore, drink masses of water all day long to preserve your frame hydrated and take your food regularly on the proper time to remain energetic. . Make your priority listing.

  16. DIY Carpet Cleaning Typical DIY cleaning involve regular carpet vacuuming, removing stains on carpet using DIY stain removal products found in hardware store, and some may even purchase or lease equipment to clean it.

  17. Gen Keto You could want to memorize and repeat some of your affirmations at some stage in the day to maintain your mind uplifted and influenced. Lose weight affirmations to apply . I am happy and lean at "clean" pounds. . I am going to pick culmination and veggies for snacks to burn fats cells. . I'm being thankful for my body and it is present day fitness. . I'm workout five times a week to prevent more fat cells from forming. . I am toning and strengthening my frame times per week to slim my waistline. . I'm working towards to analyze a brand new "clean" (sport or interest) . I am going to prepare meals beforehand of time to devour healthy meals. .

  18. Ultra Fast Keto This is simply one opportunity medicine that you could have a look at on the subject of this kind of treatment. You may find that rub down also can be very relaxing so you will certainly be getting more for your money when you prevent and consider it. Mike jansen is a creator manufacturer of online and offline content. You may test out his modern day website at approximately cellulite revoval it can be very tough for an obese individual to get started in a brand new exercising software. Years of a sedentary life-style are hard to conquer. But not impossible.

  19. Massive Male Plus In this look at, men with hyperthyroidism had been times more likely to have erectile troubles as compared to "standard" guys. An earlier take a look at found that guys with both circumstance also had other penis health troubles, inclusive of an elevated probability of untimely ejaculation and low libido. (apparently, a few men in this organization additionally had a trouble with not on time ejaculation.) treatment guys with thyroid issues shouldn't despair, however; maximum guys reply favorably to remedy, and often the penis health issues related to thyroid issues are resolved whilst the thyroid gets returned to operating "normally."

  20. Fantastic Keto While a person is unable to sleep, it may substantially have an effect on their whole existence with their temper and the manner that they feel every day. A few docs sense that some individuals who devour like this aren't getting enough fiber in their weight loss program. This will purpose problems but nothing has been validated but. Youngsters and adults can consume these meals and sense higher. They'll have enough strength to participate in sports and be very a hit. There are numerous people who've lost a variety of weight. This is one aspect which could help someone sense better as well as make the aches and pains depart because the joints could be bearing much less weight. There are risks to changing to any sort of weight loss program.

  21. CBD Miracle Pain Patch In west palm beach, we get a ton of thunderstorms so ache sufferers have the unlucky opportunity to revel in this often. Scientists tested this idea on guinea pigs and rats. They separated the animals into groups. The first organization had ache with artificially low air strain. The second one organization had ache with everyday air pressure. They located that the low pressure animals showed accelerated ache behavior in comparison to the controls. This is crucial due to the fact you can not sway or convince an animal that lower pressure goes to lead them to hurt greater.

  22. Massive Male Plus to permit an elevated flow of blood in. The penis swells with blood and an erection is the end result. In case you don't get enough of this key chemical, you may in no way get an erection, not to mention a tough one. Your kingdom of thoughts also performs a key function and stress, tension and fatigue impact on body power degrees, while strength degrees drop, so does libido. The above are all not unusual issues and the first-rate herbal intercourse tablets; combo a cocktail of demonstrated herbs