Note that there are some explanatory texts on larger screens.

plurals
  1. POBizarre NSSet copying crash
    primarykey
    data
    text
    <p>I have a class that contains an <code>NSSet</code>. That object is called <code>_collectibles</code>, and in a method, I make a copy of that set in order to do some processing, something like:</p> <pre><code>NSSet* collectibleCopy = [_collectibles copy]; </code></pre> <p>In practice, I see this regularly crash with this message:</p> <pre><code>[__NSPlaceholderSet initWithObjects:count:]: attempt to insert nil object from objects </code></pre> <p>I've resolved the issue by changing the above code to:</p> <pre><code>NSMutableSet* collectibleCopy = [[NSMutableSet alloc] initWithCapacity: [_collectibles count]]; for ( id thing in _collectibles ) { [collectibleCopy addObject: thing]; } </code></pre> <p>And now I can no longer reproduce any such crash. I'm betting <code>[copy]</code> is more efficient, and I'd rather use it, but I can't figure out why it's completely wonky!</p> <p>Update: while full context would take a ton of explanation, the keys to me solving this were that, a, the code was invoked this way:</p> <pre><code>NSBlockOperation* operation = [NSBlockOperation blockOperationWithBlock: ^{ [thing doStuff]; }]; [operationQueue addOperation: operation]; </code></pre> <p>And that I was, basically by making a bunch of things slower, catch the app with 2 threads running 2 threads for a queue initialized thusly:</p> <pre><code>operationQueue.maxConcurrentOperationCount = 1; </code></pre> <p>Which I thought impossible. The clue was that the second thread was in [NSAutoreleasePool drain], which led me to learn that NSOperationQueue can do autorelease stuff whenever/however it wants.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload