Memory management was a hot topic in computer science…20 years ago. The need to understand this area was made less important because most of today’s programming languages have automatic “garbage collection.” This automation freed the programmer from having to mentally track how much memory had been requested and should be released when no longer needed. Modern computers can have gigabytes of RAM and essentially unlimited amount of virtual memory. All of these factors have made software easier to write, but not necessarily “cleaner” when running.
Small devices such as cell phones, PDAs, and iPods have limited physical memory, no swap space, and primative operating systems. Most do not tolerate memory leaks well, if at all. Chapter 3 of the Brain-Friendly Guide to iPhone Development broached the subject of memory-management on the iPhone and iPod Touch. It has been a while since WE had to pay attention to it so we spent a bit of time getting through the details of “reference counting.” The big reason is apps with memory leaks will not be approved by Apple for listing in the App Store…a pretty strong incentive to make sure the leaks were plugged before submitting them for approval.
Memory-management was introduced in Chapter 3 because it was the “right” time. Sooner or later, we had to understand when to free up memory which we no longer needed, the difference between “autorelease” and doing it explicitly, and the consequences of doing it wrong. While important, it was pretty dry stuff.
The book did do a good job of presenting it a few different ways. Most of it made sense, but we are not sure how much of it actually stuck. Once we got past the memory thing, the rest of the chapter got “fun” again. The next task was to add a TextField to the InstaTwit app. We’ll show you how we did in the next installment.