Skip to content

Conversation

@xushuangqing
Copy link

Hello,

When using FBRetainCycleDetector on iOS 14, I got frequent crash. The stack is:

MACH_Exception EXC_BAD_ACCESS KERN_INVALID_ADDRESS fault_address:0x000000014521c678
0libobjc.A.dylib
_objc_loadWeakRetained (in libobjc.A.dylib)
1 MyApp                -[FBObjectiveCGraphElement object] (in NewsInHouse) FBObjectiveCGraphElement.h:41
2 MyApp                -[FBObjectiveCGraphElement isEqual:] (in NewsInHouse) FBObjectiveCGraphElement.mm:91
3 MyApp                -[FBNodeEnumerator isEqual:] (in NewsInHouse) FBNodeEnumerator.mm:51
4 CoreFoundation -[__NSSetM containsObject:] (in CoreFoundation)
5 MyApp                -[FBRetainCycleDetector _findRetainCyclesInObject:stackDepth:] (in NewsInHouse) FBRetainCycleDetector.mm:117
6 MyApp                -[FBRetainCycleDetector findRetainCyclesWithMaxCycleLength:] (in NewsInHouse) FBRetainCycleDetector.mm:65

It typically happened when the candidate is a PHAsset object. When FBObjectiveCGraphElement->_object becomes a _PFResultASCIIString, crash happened.
image

in iOS 14, PHAsset has instance variables whose classes are _PFResultASCIIString. Below is one PHAsset's retained objects:

Printing description of retainedObjects:
<__NSArrayM 0x282aac270>(
-> _cloudAssetGUID -> _PFResultASCIIString ,
-> _creationDate -> __NSTaggedDate ,
-> _modificationDate -> __NSTaggedDate ,
-> _uniformTypeIdentifier -> _PFResultASCIIString ,
-> _directory -> _PFResultASCIIString ,
-> _filename -> _PFResultASCIIString ,
-> _imageRequestHints -> _PFResultData ,
-> _faceAdjustmentVersion -> __NSTaggedDate ,
-> _uuid -> _PFResultASCIIString ,
-> _objectID -> (null) ,
-> _photoLibrary -> PHPhotoLibrary 
)

_PFResultASCIIString may be a new private class from iOS 14. It is a subclass of NSString, but it has some strange behaviors. As malloc_zone_from_ptr(pfResultASCIIString) returns null. It seems _PFResultASCIIString is not a malloced object.

I suppose, if an object is not malloced/realloced, checking by FBRetainCycleDetector is meaningless. So I added a condition to filter objects that are not malloced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants