Tag Archives: GC

Garbage collection

Now some of you familiar with this movie might think, how is this related to anything in my computer and how the  fudge did he get there? Very simple, I'm talking about his job which is garbage collecting. The garbage collector in your computer is probably something what many programmers praise to, as it's made their lives just that bit nicer. Before GC (Garbage colletion) programmers had to do manual memory management. What it does can be explained quite easy, yet the whole process of doing so might just be a little harder to understand. What GC does, it finds data objects in a program that aren't of any use anymore, after it found those objects it will tag them, meaning that they can be overwritten with new data. Advantages of this way of memory management are obvious, without the need of manual memory management the chances of making mistakes are significantly reduced. With manual GC you might try to free space that has been freed before and possibly been assigned again, resulting in bugs in your program.

How does the GC know what fine memory units to take with him? In the coding it knows when an object is in use, not being used at the moment, or never to be used again.

Dim x as string
Dim y as string
dim x as double
y = "Please don't take me"

 

In this example we can safely state that after x became a 'double', there was no need  for the String anymore. x has been overwritten if you want. But the y string is still in use later in the program so it's best to keep both of these in the memory.

So how do programming languages know about the GC? Most of the higher-level programming languages are likely to have it built-in as a standard feature (Fortran, C#, Pascal, etc..) and even if some languages don't have it built-in, it can be added trough libraries.

This is quite a simple view of what garbage collection is, why we have it and love it, and how it works.