JVM e Garbage Collection

Oi Pessoal, tudo bem? Starting here the 1º blog post, I’m going to try to create a opuscule (i.e., a wee text) about Garbage Collection e the Java Virtual Machine. My objective here is to avoid writing something boring, so I expect that something should be added and/or corrected in the comments section afterwards.
For you that never programmed even a pathetic HelloWorld class and whoever wants to reinforce what have learned during the SCJA (Sun Certified Java Associate) studies, here is the first universal truth:

The JVM is Chaotic

The Garbage Collection is not performed immediatly after an object loses its reference, the JVM waits until a few lost objects start to accumulate. Think of it as a Cleaning Lady that is watching TV and, after her boss’s children finished their fun activities on the living room she decides (whenever she wants) to collect the toys, sweep, vacuum the carpet (i.e., GC).

stack_and_heap

Look at the image above, on the left side we have the Stack (where the reference variable is) and on the right side we have the Heap (where the actual object is), if we add the following line of code:

my_birth = null;

Our cleaning lady will already know that, at some point in time, she will have to take care of that useless object that was left in ‘0x01abcdef’, we can’t do anything about it, just ask nicely:

System.gc();

In other words, “Hey Consuela, can you please clean that room over there?” (but that will only make her give more attention to that particular region, she will not do anything immediately).

So, how does the GC works? Well, we know that GC will occur on objects that do not have references, so the first algorithm that we should talk about is the “Mark and Sweep”.

3 thoughts on “JVM e Garbage Collection

  1. Pingback: Nashorn and the JVM monitoring challenge – Part 1 | MarceloRJava

  2. whoah this weblog is fantastic i love studying your posts.
    Keep up the great work! You know, a lot of
    individuals are looking round for this info, you can aid them greatly.

  3. I was excited to find this great site. I want to to thank you for
    ones time just for this wonderful read!! I definitely appreciated every little bit of it
    and I have you book-marked to see new stuff on your web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s