Visualizing Garbage Collection Algorithms

Most developers take automatic garbage collection for granted. It’s just another amazing feature provided by our language run-times to make our jobs easier.

But if you try to peek inside a modern garbage collector, it’s very difficult to see how they actually work. There are thousands of implementation details that will confuse you unless you already have a good understanding of what it’s trying to do and how they can go fantastically wrong.

I’ve built a toy with five different garbage collection algorithms. Small animations were created from the run-time behavior. You can find larger animations and the code to create them at It surprised me how much a simple animation reveals about these important algorithms.

Cleanup At The End: aka No GC

The simplest possible way of cleaning up garbage is to just wait until a task is done and dispose of everything at once. This is a surprisingly useful technique, especially if you have a way of breaking up a task into pieces. The Apache web server, for example, creates a small pool of memory per request and throws the entire pool away when the request completes.

The small animation to the right represents a running program. The entire image represents the program’s memory. Memory starts out colored black, which means it isn’t used. Areas that flash bright green or yellow are memory reads or writes. The color decays over time so you can see how memory was used, but also see current activity. If you watch carefully, you can see patterns emerge where the program begins to ignore some memory. Those areas have become garbage — they are not used and not reachable by the program. Everything else that isn’t garbage is “live”. Read more on Visualizing Garbage Collection Algorithms…

Kicking the Tires on Ruby 2.1 Preview

A preview of Ruby 2.1 was released a couple of days ago with these release notes:

VM (method cache)
Decimal Literal
Frozen String Literal
def’s return value
new Rubygem

I found myself scratching my head for a minute. I don’t know what most of these are! So let’s dig into them and dive into some of the details.

Read more on Kicking the Tires on Ruby 2.1 Preview…

Problem-Solving Like a Generalist

I develop embedded software, but if you look on my coffee table, you’ll see books on a wide variety of programming topics — information retrieval, garbage collectors, and so on. This would strike some people as strange. Shouldn’t I be focusing on electronics or something?

Yes and no. I consider myself an “embedded specialist,” and I focus most of my time (and professional development energy) on that field. And yet, I believe the best way to stay creative is to learn new things and think in new ways. When you see a problem through the lens of another field — and approach it using the tools of that field — new possibilities invariably open up. This is why AO makes a point of hiring generalists; they’re better prepared to make these connections.

Read more on Problem-Solving Like a Generalist…

Using Backbone.js Support

Backbone.js is a powerful framework. If you’ve been following our blog, you have most likely noticed that we use it a lot. If you don’t have much background in it, take a look at the Backbone.js homepage or some of our articles to get you started. Although Backbone.js is powerful it lacks an automated way to clear views and unbind event bindings for garbage collection. With the help of a an extension known as Backbone Support, it’s easy to build views that automatically clean themselves up.

Read more on Using Backbone.js Support…