Our staff spent the past couple days updating Goldenseal Pro to use ARC (Automatic Reference Counting). It’s a nifty feature that is Cocoa’s third generation of memory management. We actually thought it was already turned on by default. But, while checking some other compiler settings this week, we discovered it wasn’t.
Memory is a big deal to programmers. As Goldenseal runs, we create thousands of objects. Each is a chunk of memory that stores some data and does tricks. We give each object a name, then the operating system decides where it will live in RAM.
In C++, we need to decide when each object dies. If we kill it too soon and try to use it after it’s dead, Goldenseal will crash. If we forget to kill it, there will be a memory leak. Accumulate too many leaks, and the app will consume more and more RAM. Eventually the program will get very slow. It may even consume all available memory and crash.
Fortunately, modern C++ has many tools for managing memory, to make sure each object is deleted properly. They help Goldenseal to leak very little, and almost never crash. Some other software is not so careful. For example, most web browsers are very leaky. Use them all day, and they will gradually use up many megabytes or even gigabytes of memory.
Cocoa used to require manual memory management, similar to C++ (but without the modern tools to help). In the mid-2000s it added garbage collection (also a feature of Java and many other programming languages). Garbage collection prevents leaks by periodically checking every object, and killing it if it’s no longer being used. That prevents leaks, but also can be annoying. If you ever have an app suddenly stop dead for several seconds, its garbage collector probably is “emptying the trash”.
Apple added ARC in 2011. It automatically kills each object when nothing else uses it any more. For example, dozens of objects die whenever you close a window. It makes memory one less thing to worry about.
For ARC to work, we had to add a __bridge keyword, every time we convert between C++ and Objective-C. The compiler colors it bright green. It’s actually kinda nice to have it in the code. The conversions are risky, and anything that makes them more obvious is a good thing.
In general, our staff spends a lot of time looking at brightly colored text. Source code is a huge mass of comments, objects, functions and programming commands. It can be overwhelming. A bit of color coding really helps.
Dennis Kolva
Programming Director
TurtleSoft.com