On Memory Management

Many iOS developers will agree that once you get past the syntax quirks of Objective-C, the most unfriendly aspect of the  language is memory management.  If you aren’t a programmer, you can think of memory management like it’s a closet:

Closets are full of items collected over time – some of the things in them are important and some aren’t.  Once your closet gets too full, you can go in and pull out all of the old items that you don’t need anymore and throw them in the trash to make room for new ones.  Many modern languages have the programming equivalent of a housekeeper – they look through the closet and toss the old items without you having to do any work.  Objective-C, though, doesn’t have a housekeeper – if you don’t manually clear out your old items, your closet overflows and your program might crash.

Conceptually this isn’t a problem, but during development it can be quite a headache to properly release all of your memory after you finish using it, especially if you have a lot of objects in your game.  As an example, it took quite a while to figure out that the Cocos2d framework we are using automatically frees up memory from old images that you don’t need anymore, but it doesn’t automatically free up memory from old animation frames.  After adding code to do this process manually, Grow Your Garden runs with much less memory usage than before.  And that’s the upside of manual memory management – despite the added development pain, you end up with faster games that can run on less sophisticated hardware.

Like this post? Like us on facebook, too!

Category : Blog

Comments are closed.