Finding Memory Leaks in Cocoa + Objective-C

I found and fixed a memory leak in Poker Copilot’s HUD this afternoon. That’s the satisfying way I like Fridays to end.

A small component of Poker Copilot is written in Objective-C and Cocoa, the standard tools for Mac OS X programs. (The rest of Poker Copilot is written in Java). In Java, all the memory is cleaned up automatically using Java’s absolutely amazing and astounding garbage collector. For the first few years of Java, its garbage collector was primitive and caused long-running Java programs to freeze for some seconds from time to time. These days, however, the Java garbage collector is a programming work of art, working seamlessly, efficiently, and – most important of all – invisibly.

I’ve got used to that world. So moving into Objective-C, where I have to manually make sure memory is released seems like a jump back a decade or two in time. There is a garbage collector in Objective-C, but it produces code for Mac OS X 10.5+. When I tried to move Poker Copilot away from OS X 10.4 (Tiger) I had the virtual equivalent of an angry mob outside the front door, demanding justice for all. Well, for all the members of the angry mob!


And so, the Poker Copilot HUD had a memory leak. With the help of Xcode, Instruments, and this excellent blog post, I was able to find the leak and banish it forever. And hold of the angry mob.

Now back to the nice world of Java.

FastSpring and Credit Card Fraud

A few weeks ago, someone tried to buy Poker Copilot with a credit card. FastSpring, my payment processor, declined the transaction. A couple of minutes later, someone else tried to buy Poker Copilot with a credit card, and FastSpring also declined that transaction.

What did these two attempted purchases have in common, apart from both being declined? The same IP address. In non-tech talk, that means both attempted purchases came from the same computer (or, perhaps, the same computer network).

Over the next 15 minutes or so there were several more attempts from the same IP address to purchase Poker Copilot with a range of different credit cards and names. It was suspicious, FastSpring detected this, and stopped the seemingly fraudulent sales from going through.

This illustrates an important reason to use a solid payment processor for online sales. Rolling good fraud protection yourself is simply too hard. And yet when you do all your business online you need good fraud protection.

Does Poker Copilot have Ongame Network Support?

In the last week or so, I’m getting this question every day. Ongame Network has released a Mac client and now people want to know: Will we be adding Ongame support to Poker Copilot?

So, here’s the official answer: We’re considering Ongame support but have no firm plans yet. After Poker Copilot 2.0 is released, we’ll investigate whether it’s possible.

Poker Copilot 2 Early Access Program Update

For the curious, Poker Copilot 2 early access version build 7 is available at http://pokercopilot.com/eap

What’s changed:

  • you can filter by game type (limit, no limit, pot limit, cap limit)
  • the HUD is more robust
  • small tweaks based on your feedback
  • plenty of bug fixes based on crash reports (keep them comin’!)
  • Tools -> Turbo Load builds your database faster by suspending all other features

Known problems:

  • when switching between tables, the HUD shows data from the wrong table for a few seconds
  • charting by hands is unavailable

You can run the EAP version without affecting Poker Copilot 1 at all.

Why does Poker Copilot talk to the Internet?

An anonymous (but hopefully loyal) Poker Copilot user asks:

Little Snitch shows some Internet sites that Poker Copilot connects to. Could you explain this in some detail?

Sure thing, anonymous.

  • Once a week Poker Copilot checks for an updated version at http://pokercopilot.com/. You can turn this off in the Poker Copilot preferences.
  • If you agreed to Usage Tracking when you installed Poker Copilot, then Poker Copilot efficiently and quietly sends the name of each feature you use to our feature tracking server. It also sends a session id with each feature, so that we can tell, for example, how long people tend to use Poker Copilot. No identifying information is sent. The server is called hotfeatures.barbarysoftware.com and is owned and operated by me. You can turn this off in the Poker Copilot preferences.
  • Poker Copilot accesses a time server when the HUD is started. In order for the HUD to work reliably, Poker Copilot ensures your computer date, time, and timezone are set accurately. Poker Copilot 1 accesses the US naval observatory site (http://tycho.usno.navy.mil/cgi-bin/timer.pl) to determine the accurate time using HTTP. Poker Copilot 2 will access an NTP server using the Network Time Protocol at start-up, and automatically offset dates/times by any observed inaccuracy. I haven’t yet decided what time server to use in production, but in development it’s time.apple.com

The world of always-on broadband Internet gives software developers great opportunities for creative solutions to problems. I may add some more background features that use the Internet in the future. But always for good, not evil!

Poker Copilot’s Crash Reporter

Let’s say that double-clicking on Poker Copilot’s “Position Summary” screen crashes Poker Copilot one time in 100. To find this bug, I’d have to use the screen a lot. Many times to cause the bug, and many times more to reproduce the bug. But if 100 people used the Position Summary screen in one day, chances are that the bug would rear its head at least once most days.

To help track down some obscure issues like this, I added a Crash Reporter to Poker Copilot 2 a couple of weeks ago. If Poker Copilot crashes, the Crash Reporter springs to life, notifying the user, and offering them a chance to send the crash report to Poker Copilot international headquarters. Location: my home office.

The crash report sends the error message plus a snapshot of the state of Poker Copilot. (For the techies: a stack trace and thread dump, plus assorted system properties.)

I’m now getting several crash reports a day, and lordy me, are they ever helpful. That hypothetical once-in-a-100-times bug I described above? It wasn’t hypothetical at all. It was very real, and with the help of crash reports I mercilessly murdered it.

Sentence of the Day

From Joel Spolsky’s latest article in Inc. Magazine.:

I feel like I finally understand what Jeff Bezos meant in 1999 when he described Amazon as facing “insurmountable opportunity.”

I sometimes get the feeling myself that there are too many possible directions, ideas, and opportunities. It’s a nice feeling!