NSPointerArray weird compaction

The reason this happens is that -compact first checks whether an internal flag 'needsCompaction' is set. If it's not, it simply bails early. The only time the flag is set is if a nil pointer is inserted directly into the array through the public interface. It does not get set if a weakly referenced object is deallocated (and the pointer is nil'd) after the pointer was inserted into the array.

One work around for this behavior is to purposefully append a nil pointer to the array before calling -compact. Not ideal but it'll work.

[pa addPointer:nil]; // forces the pointer array to do compaction next time
[pa compact];

I've seen this same behavior. Here is an open radar bug report: http://www.openradar.me/15396578