objective c - NSPointerArray weird compaction -


i have weak nspointerarray nsobject has been released. before calling compact see is:

(lldb) po [currentarray count] 1 (lldb) po [currentarray pointeratindex:0] <nil> (lldb) po [currentarray allobjects] <__nsarraym 0x16f04f00>(  ) 

that makes sense, weird when call compact on array see same values! count still returns 1 , pointeratindex:0 nil.

why nil hasn't been removed?

edit

here's full code (yeah it's xctesting framework):

- (void)testcompaction {     __weak id testingpointer = nil;      nspointerarray *weakarray = [nspointerarray weakobjectspointerarray];      @autoreleasepool {          nsobject *someobj = [[nsobject alloc] init];          testingpointer = someobj;          [weakarray addpointer:(__bridge void*)testingpointer];          nslog(@"before compaction inside autorelease: testingpointer = %@ count = %d, allobjects = %@, pointeratindex:0 = %@, pointeratindex:0 class = %@", testingpointer, [weakarray count], [weakarray allobjects], [weakarray pointeratindex:0], [(id)[weakarray pointeratindex:0] class]);          someobj = nil;     }      nslog(@"before compaction outside autorelease: testingpointer = %@ count = %d, allobjects = %@, pointeratindex:0 = %@, pointeratindex:0 class = %@", testingpointer, [weakarray count], [weakarray allobjects], [weakarray pointeratindex:0], [(id)[weakarray pointeratindex:0] class]);      [weakarray compact];      nslog(@"after compaction outside autorelease: testingpointer = %@ count = %d, allobjects = %@, pointeratindex:0 = %@, pointeratindex:0 class = %@", testingpointer, [weakarray count], [weakarray allobjects], [weakarray pointeratindex:0], [(id)[weakarray pointeratindex:0] class]); } 

and logs:

  before compaction inside autorelease: testingpointer = <nsobject: 0x7de7ff80> count = 1, allobjects = (     "<nsobject: 0x7de7ff80>" ), pointeratindex:0 = <nsobject: 0x7de7ff80>, pointeratindex:0 class = nsobject 2015-07-20 14:27:14.062 appetizesuite copy[54144:9019054] before compaction outside autorelease: testingpointer = (null) count = 1, allobjects = ( ), pointeratindex:0 = (null), pointeratindex:0 class = (null) 2015-07-20 14:27:22.615 appetizesuite copy[54144:9019054] after compaction outside autorelease: testingpointer = (null) count = 1, allobjects = ( ), pointeratindex:0 = (null), pointeratindex:0 class = (null)    

why compact method not delete first pointer? it's nil before calling compact.

i've seen same behavior. here open radar bug report: http://www.openradar.me/15396578


Comments