objective-cautomatic-ref-countingdistributed-objectsnsconnection

Objective-C Distributed Objects with ARC sever and 32bit proxy?


I have a 64bit application using ARC, that is serving up a distributed object. The application that uses the proxy object is a 32bit application, so it's not using ARC. Is this going to create problems for me?

I also want to reuse my classes from the 64bit/ARC application, inside my 32bit application. If those are ARC, how can I integrate them in a non-ARC application?


Solution

  • I would not recommend doing this. Using distributed objects between the 32-bit and 64-bit runtimes appears to be possible, but it has some problems. From the Foundation Constants Reference:

    Prior to Mac OS X v10.5, NSNotFound was defined as 0x7fffffff. For 32-bit systems, this was effectively the same as NSIntegerMax. To support 64-bit environments, NSNotFound is now formally defined as NSIntegerMax. This means, however, that the value is different in 32-bit and 64-bit environments. You should therefore not save the value directly in files or archives. Moreover, sending the value between 32-bit and 64-bit processes via Distributed Objects will not get you NSNotFound on the other side. This applies to any Cocoa methods invoked over Distributed Objects and which might return NSNotFound, such as the indexOfObject: method of NSArray (if sent to a proxy for an array).

    Sure, you can do some basic sanity checks on -[NSArray indexOfObject:], but what if any library or framework you use (which includes Cocoa and Foundation) uses an API that can return NSNotFound? Not to mention that this is only one problem that can occur communicating between 32 and 64-bit runtimes, and the other problems might not be documented.

    I tend to shy away from distributed objects because of some of their other problems, but even if you were determined to use them, this seems like a deal breaker to me.

    I do not believe that there is anything intrinsic to ARC that would prevent you from using ARC and Distributed Objects together. However, memory management with distributed objects can be tricky. If you needed to break the standard retain-release rules to work around a memory leak between the client and the server, ARC would not let you do so. You'd need to be extra careful to architect your server to avoid this.

    Finally, since you can't use ARC in your 32-bit runtime, you'll have to write manual retain/release code for those classes. If you plan to eventually move away from the non-ARC code, you can advantage of __has_feature(objc_arc). Otherwise it's probably better to not use ARC on the files you plan to share between the 32 and 64-bit applications. ARC can be enabled or disabled on a per-file basis.