Memory Management – Part 3

So I finally have a little bit of time after the Christmas rush to finish off our 3 part post on memory management (see Part 1 and Part 2), by looking at garbage collection. So let’s dive in…

Garbage collection is a feature available to a number of programming languages, most notably .NET languages (e.g. C#), Java and Objective-C (though not currently available on iOS). Basically, garbage collection is kind of like, well, real life garbage collection. When you’re finished with something, you discard it, and at some point in the future everything you’ve discarded will get cleaned up by someone else (i.e. The garbage collector). Sounds like a perfect system, right? Just create what you want, discard it when you’re done and not worry about memory management. Unfortunately, a lot of people (myself included) soon come across the pitfalls of this approach, but with a little knowledge you can play nice with the garbage collector. Firstly, we’ll take a look at how garbage collectors generally work, then at some of the problems we can find ourselves in, and finally the solutions…

Continue reading