You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So the idea is ASDataController has the strong reference through the map(s) and the node has a weak reference to prevent a cycle. OK, great.
Now let us consider ASDataController.updateWithChangeSet, which, we should note at this time, asynchronously executes the block which is frame 22 in the crashing stack above.
The events leading up to this are as follows:
I assume this comment to be true:
// Since we waited for _editingTransactionGroup at the beginning of this method, at this point we can guarantee that _pendingMap equals to _visibleMap.
So now both _pendingMap and _visibleMap contain a strong reference to the ASCollectionElements in question:
Note that _visibleMap is the last guy to maintain a strong reference. Continuing:
dispatch_group_async(_editingTransactionGroup, _editingTransactionQueue, ^{
// Step 3: Layout **all** new elements without batching in background.
NSArray<ASCollectionElement *> *unmeasuredElements = [ASDataController unmeasuredElementsFromMap:newMap];
[self batchLayoutNodesFromContexts:unmeasuredElements batchSize:unmeasuredElements.count batchCompletion:^(id, id) {
ASSERT_ON_EDITING_QUEUE;
[_mainSerialQueue performBlockOnMainThread:^{
[_delegate dataController:self willUpdateWithChangeSet:changeSet];
// Step 4: Deploy the new data as "completed" and inform delegate
_visibleMap = newMap;
Now _visibleMap has released its strong references as well. At this point, sometimes, if one implements dealloc for ASCollectionElement and sets a breakpoint there, you will see them get deallocated.
I'm honestly not sure how this ever works other than we get lucky with the autorelease pool. Though this code is pretty complicated and I don't fully understand all the moving pieces. All I know is this is biting me. Let me know if you have any questions.
The text was updated successfully, but these errors were encountered:
@jeffdav Thanks for making an incredibly detailed and easy-to-follow investigation into this issue. I think the attached diff will fix the issue in a sane way.
Using the current Texture CocoaPod (2.3).
I'm removing two nodes in a batch update:
Before the completion block is invoked, I sometimes (~60% of the time) crash here:
The crash is because we pass
nil
tolayoutAttributesForItemAtIndexPath
. At the point we throw:...observe:
Popping up the stack, at:
...observe:
Investigation shows that
ASCellNode.collectionElement
is declaredweak, nullable
:And, as far as I can tell, they are only ever stored in
ASDataController
's element maps:So the idea is
ASDataController
has the strong reference through the map(s) and the node has a weak reference to prevent a cycle. OK, great.Now let us consider
ASDataController.updateWithChangeSet
, which, we should note at this time, asynchronously executes the block which is frame 22 in the crashing stack above.The events leading up to this are as follows:
I assume this comment to be true:
So now both
_pendingMap
and_visibleMap
contain a strong reference to theASCollectionElement
s in question:Continuing:
Now mutableMap does too. Continuing:
Now mutable map does not.
Now note the objects have been removed:
Continuing:
Now
_pendingMap
andmutableMap
andnewMap
have all given up their strong references:Note that
_visibleMap
is the last guy to maintain a strong reference. Continuing:Now
_visibleMap
has released its strong references as well. At this point, sometimes, if one implementsdealloc
forASCollectionElement
and sets a breakpoint there, you will see them get deallocated.Continuing:
And this is where we are in stack frame 22.
I'm honestly not sure how this ever works other than we get lucky with the autorelease pool. Though this code is pretty complicated and I don't fully understand all the moving pieces. All I know is this is biting me. Let me know if you have any questions.
The text was updated successfully, but these errors were encountered: