Last week I mentioned a mystery problem we were fighting: the outline view in our main window used to work OK. Then suddenly, it didn’t.
Folks on the Cocoa-dev mailing list were very helpful, with many suggestions on what might fix it. We tried them all, but nothing worked. Along the way our staff learned way too much about Apple’s memory system. It’s called ARC (Automatic Reference Counting). Developers on the list think it’s the bees knees. It is certainly better than the old manual system. Except that ARC was deleting our outline view, even though code was there to prevent it.
These days, most programming languages manage memory automatically. Stuff sticks around as long as you need it, then disappears when it’s no longer needed. Popular languages like Java, Python and C# use “garbage collection” to accomplish that. It’s probably not the ideal way to manage memory, but it works fairly well. And it makes life much, much easier for programmers.
Most of Goldenseal is written in C++. It is considered a difficult language, mostly because it doesn’t have garbage collection. On the other hand, C++ does give better performance. It’s also fairly easy to debug. There are many ways for programmers to manage memory reliably, and the language keeps improving every year.
Using C++ is a bit like, say, using power tools. Sure, they have sharp whizzing parts that can easily remove your limbs or digits. But they include guards and safety features. If you use power tools carefully, they get the job done safely.
Apple’s ARC seems to be somewhere in between C++ and Java. It promises easy memory management, but there are many “gotchas” that we discovered this week. It is not easy to debug. It definitely is not as simple as the garbage-collected languages. That applies both to the Objective-C language that we use for the new Goldenseal code, and to Apple’s new Swift language.
I hate to criticize a trillion-dollar company, but our life would be way easier if Apple used C++, Python, Java, or pretty much any other programming language. There’s a reason everyone else uses those other languages.
At any rate, we did find a fix. Our code worked OK until we made changes in June, and we can revert those changes. Theoretically it will leak some memory, but it won’t be very much. It won’t happen at all for most users.
With hindsight, we could have just reverted right away, and saved two weeks. But we learned stuff along the way. It was good to find out we hadn’t done anything obviously stupid. If our staff did cause the problem, it was something extremely subtle. It may even be a bug in Apple’s ARC code, though it’s not worth another week of digging to find out for sure.
At least Goldenseal Pro is back on track. This is not the first time we’ve bogged down in Cocoa complexities, and lost weeks or months.