Moral of the Story (Part 2ish)

March 5th, 2008 by Joe Ranieri

On a somewhat related topic from last time, I thought I’d mention some other nasty hacks I’ve seen passed off as safe.

Pre-emptive Threading

There are several libraries that claim to offer this in REALbasic. The problem is that it can’t be done. The RB runtime simply isn’t thread safe, not to mention the framework itself!

Something as trivial as referencing a string has the potential to bring down your whole application in bizarre and difficult-to-detect ways. Even if your code doesn’t directly touch the runtime, the code the compiler generates might. The rules on when it does so (to yield to another thread, for example) are undocumented and extremely likely to change from version to version.

To make a long story short: it’s a bad idea.

Weak References

Another library implemented weak references in a horrible manner. They simply unlocked the object and returned it, decrementing its reference count.

At first glance this would appear to work - your object goes away even if another object holds a weak reference to it. However, the problem occurs if you attempt to access the “weak reference” after its original object goes away. This will almost certainly crash your program.

The problem is that your “weak reference” still points to the place in memory where the object lived. By the time you use your “weak reference,” REALbasic has most likely already tossed something else in that location.

To make a long story short: it’s a bad idea.


COMMENTS

One Response to “Moral of the Story (Part 2ish)”

  1. Norman Says:

    Hmmmm …. I can guess at one of these as I’m fairly sure I know which plugin does at least one of these things

Leave a Reply