Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSHashTable count incorrectly reports non-empty

I'm using a weak objects NSHashTable that is reporting a count of 1 even though it's empty. The following is lldb output displaying my case.

p [__operationWaitList count]
(NSUInteger) $4 = 1

p [__operationWaitList.allObjects count]
(NSUInteger) $7 = 0

My best guess is that count counts the number of weak references stored in the NSHashTable rather than the number of valid objects. By calling allObjects however I'm dereferencing the pointers which uncovers that there are no valid objects, hence the resulting object array is empty.

I'd like confirmation of this since the documentation is a bit lacking on this point.

like image 754
greg Avatar asked Apr 26 '15 16:04

greg


1 Answers

Experimental results, non-exhaustive testing, suggest:

  • Your observation is correct, count returns the number of references currently in the hash table some of which may be null.

  • Also as you observed allObjects.count always returns the number of non-null references.

  • Adding a new distinct object appears to cleanup null references.

Documentation is not clear on the issue.

Suggest you file a bug report with Apple, they should either fix the implementation or the documentation.

like image 92
CRD Avatar answered Oct 16 '22 17:10

CRD