addObjectIfAbsent: and slow EOF Performance

Creation Date: Feb 25, 1998
Keywords: EOF, NSMutableArray, Notifications, Performance

This document describes a problem that can cause memory leaks and slow performance for OPENSTEP applications.  The problem occurs because Apple's EOF framework uses a category to add an addObjectIfAbsent: method to NSMutableArray.

@interface NSMutableArray (EOPointerBasedManipulation)
- (BOOL)addObjectIfAbsent:object;
    // adds an object to the array if and only if it isn't already in the array
    // return YES if object was not in the array or NO if it already was present
@end

Because this method is not documented, some Apple developers and writers of third-party frameworks have added their own addObjectIfAbsent: method.  When EOF's EOObjectStoreCoordinator makes a call to addObjectIfAbsent: to register a notification, it does not receive the expected return value, and two additional notifications are generated.  This can seriously affect system performance in applications which make a large number of database fetches.  There are three possible solutions to the problem:

--Modify your implementation of the method to return the appropriate values, as shown above

--Modify your code to use Apple's implementation of this method

--Change the name of your custom method so Apple's implementation is not superceded.