Closed jmousseau closed 3 years ago
I forgot to say the CFDataRef
also leaks, but the fix requires a copy.
+ CFDataRef sourceData = CFDataCreate(NULL, imageBytes, self.bufferView.length);
- CFDataRef sourceData = CFDataCreateWithBytesNoCopy(NULL, imageBytes, self.bufferView.length, NULL);
imageSource = CGImageSourceCreateWithData(sourceData, NULL);
+ CFRelease(sourceData);
I was hesitant to make the change as I noticed the SCNScene
sometimes pointed to GLTFAsset
buffers not managed directly by ARC, such as the CFDataCreateWithBytesNoCopy
call with bufferView
above. As a result, calling CFRelease
without performing a copy would cause a crash.
Two modifications were made locally to create an environment appropriate for leak testing. First, the
GLTFDocument
'sasset
property was removed to eliminate one reference. Second, theSCNView
'sscene
was cleared along with theasset
four seconds after the view loaded:Here's the before and after in Instruments when loading DamagedHelmet.glb:
I considered an alternative approach where the
createCGImage
helper method returned anNSUIImage
so the caller doesn't need to clean up withCFRelease
. However, it looks likeCGImageRef
may be preferred as a cross-platform image type for this code base. If that isn't the case, happy to resubmit withNSUIImage
implementation.