The magic of garbage collectors.

 I don't know if this is my last entry, at least with Clojure related topics. but, I think that if that's the case, this discussion will be as, if not more interesting than the last two publications. Everyone who has programmed in Clojure knows that this language uses the JVM. This means that it takes all the benefits of using the Virtualization of Java to compile and run code. But... have you ever questioned how does this virtualization, specially, the java garbage collector works? Yeah, me neither. Nonetheless, if you answered no, don't worry that we are not the only ones. In fact, this curiosity inspired Alexader Yakuushev to not only questioned himself how does the tool that almost every programmer uses works, but to explain to the rest of us. 

In his video, A new age of JVM Garbage Collectors introduces us to a whole new variety of concepts and abstractions that, if you're not familiarized with data structures, you may find them hard to understand. In particular, Alexander reviewed and presented 6 algorithms of treating garbage (memory management) in programming. Each one had interesting things: 

1. For instance, the manual memory management is the oldest of all but, contrary to many beliefs, it did not aged well for modern standards as old programming languages like C did.  Its most significant problems (memory leaks and errors in allocations) do promote non-safe practices for programmers and, as we reviewed in the last entry, giving freedom to the programmer is giving to him/her power to destroy its creation.

2. Automatic reference counting is fast and automatic.... it is not the principal mechanism used in programming languages used at Apple for nothing. However, this particular method do not like circles, since it can't handle cyclic references.

3, 4.  The Mark-Sweep-Compact garbage collector is the one used in Java, thus, the first iteration used in Clojure. The interesting thing about this is that it can be seen as a zombie survival scenario but with objects: kill every dead suspect. This hunting process is developed by an algorithm that is divided in two main parts: mark and sweep compact. Now, for the 4th method I would like to considered it as an extension of the third because since, in essence, it is an incremental update to it. The Evacuating garbage collector algorithm uses the mark process of the Mark-Sweep but uses an evacuate process instead of the sweep-compact. This change allowed it to be faster in execution but made nothing for the principal errors of the Mark-Sweep.  It can be hinted that it was due to this feature that Java gained its popularity. But it can be assured that it was this particular advantage that Java lost its presence power nowadays due to the fact that it pauses an application. Completely. I can't imagine how slow were apps back the that this pauses seemed as speediness. 

5. G1 GC can be considered as the attempt of Java to improve those errors. It established the idea of most object die young. This brought to the table the notion that there was too much room for things that will later be dead or dereferenced. Thus, it was logical to think in creating spaces in memory in which objects live for the needed time. Those spaces are: Eden, Survivor and Tenured. Yes, this concurrent solution made it capable to compite within modern standards. Nonetheless, pauses are still present. 

6. With concurrent standards, RedHat tried to provide a solution with their  Shenandoah garbage collector. This step-upped the game of Garbage Collectors since it introduced the idea of non-stop applications handled by races.

I know I did not explained in detail a lot of thing, but, for those explanations, we have Alex's video. As a conclusion, is interesting to see as student how low-level concepts still impact in nowadays technology. As humans, technology not creates but improves gradually with time and with the interaction of its reality.  

Comentarios

Entradas populares de este blog

Chat with Russ Olsen

Functional Programming: A present solution for future problems

Rich Hickey: "Clojure, I'm your father"