我有一个Cocoa应用程序,它使用许多NSOperationQueue
个实例来处理后台的图像。每个队列使用:
NSImage
个对象转换为CGImageRef
个实例的调用操作
CGImageRef ref = [image CGImageForProposedRect:NULL context:nil hints:nil];
一些用户抱怨该应用突然停止响应。我让他们使用ActivityMonitor.app收集流程样本。报告都非常相似。
看起来主线程正在通过自动释放池drain
,而队列/线程在调用__spin_lock
后立即停留在ImageProviderReleaseInfoCallback
。
文档说CGImageForProposedRect:
的所有参数都是可选的。如果可以从后台线程调用它们,它们不会说任何内容。也许那就是问题?我对此表示怀疑,因为它几乎适用于所有情况(我发布应用程序数百次没有问题......)
为什么队列可能卡住了?
完整流程示例:
OS Version: Mac OS X 10.6.8 (10K549)
Report Version: 6
Call graph:
1971 Thread_905 DispatchQueue_1: com.apple.main-thread (serial)
1971 0x2e6d
1971 NSApplicationMain
1971 -[NSApplication run]
1971 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
1971 _DPSNextEvent
1971 AEProcessAppleEvent
1971 aeProcessAppleEvent
1971 dispatchEventAndSendReply(AEDesc const*, AEDesc*)
1971 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long, unsigned char*)
1971 _NSAppleEventManagerGenericHandler
1971 -[NSAutoreleasePool drain]
1971 NSPopAutoreleasePool
1971 _CFAutoreleasePoolPop
1971 CFRelease
1971 -[NSImage dealloc]
1971 -[NSImage _deallocAuxiliaryStorage]
1971 -[NSCGImageSnapshotRep dealloc]
1971 _CFRelease
1971 image_finalize
1971 _CFRelease
1971 image_provider_finalize
1971 ImageProviderReleaseInfoCallback
1971 __spin_lock
1971 Thread_943 DispatchQueue_2: com.apple.libdispatch-manager (serial)
1971 start_wqthread
1971 _pthread_wqthread
1971 _dispatch_worker_thread2
1971 _dispatch_queue_invoke
1971 _dispatch_mgr_invoke
1971 kevent
1971 Thread_944 DispatchQueue_6: com.apple.root.default-priority (concurrent)
1971 start_wqthread
1971 _pthread_wqthread
1971 _dispatch_worker_thread2
1971 _dispatch_call_block_and_release
1971 ____NSOQSchedule_block_invoke_2
1971 -[__NSOperationInternal start]
1971 -[NSInvocationOperation main]
1971 -[NSInvocation invoke]
1971 __invoking___
1971 0x17a64
1971 0x244cf
1971 0x22a97
1971 -[NSImage CGImageForProposedRect:context:hints:]
1971 -[NSImage _usingBestRepresentationForRect:context:hints:body:]
1971 __-[NSImage CGImageForProposedRect:context:hints:]_block_invoke_1
1971 -[NSImage _snapshotRepForRep:rect:context:processedHints:]
1971 -[NSImage _createSnapshotRepForRep:rect:context:processedHints:]
1971 -[NSImageRep CGImageForProposedRect:context:hints:flipped:]
1971 -[NSIconRefImageRep CGImageForProposedRect:context:hints:]
1971 _ISCreateCGImageForType
1971 _ISGetCGImageRefForISImageRef
1971 _ISImageRefIterator(void*, unsigned char, short (*)(void*, void*), void*)
1971 _ISGoThruImageStorages
1971 _ISGoThruImageStorages
1971 MergeBestStorageIntoContext(void*, void*)
1971 _CFRelease
1971 image_finalize
1971 _CFRelease
1971 image_provider_finalize
1971 ImageProviderReleaseInfoCallback
1971 __spin_lock
1971 Thread_980 DispatchQueue_6: com.apple.root.default-priority (concurrent)
1971 start_wqthread
1971 _pthread_wqthread
1971 _dispatch_worker_thread2
1971 _dispatch_call_block_and_release
1971 ____NSOQSchedule_block_invoke_2
1971 -[__NSOperationInternal start]
1971 NSPopAutoreleasePool
1971 _CFAutoreleasePoolPop
1971 CFRelease
1971 -[NSImage dealloc]
1971 -[NSImage _deallocAuxiliaryStorage]
1971 -[NSCGImageSnapshotRep dealloc]
1971 _CFRelease
1971 image_finalize
1971 _CFRelease
1971 image_provider_finalize
1971 ImageProviderReleaseInfoCallback
1971 glueReleaseInfo
1971 JP2ReleaseInfoCallback
1971 _cg_JP2TearDownDecompressor
1971 _CFRelease
1971 __CFBasicHashDrain
1971 __CFDictionaryCallback
1971 _CFRelease
1971 _CGImageReadSessionFinalize
1971 _CFRelease
1971 _CGImageReadFinalize
1971 _CFRelease
1971 __CFDataDeallocate
1971 _ISReleaseStorageRef
1971 _CFRelease
1971 __CFArrayReleaseValues
1971 _CFRelease
1971 image_finalize
1971 _CFRelease
1971 image_provider_finalize
1971 ImageProviderReleaseInfoCallback
1971 __spin_lock
1971 Thread_1013 DispatchQueue_6: com.apple.root.default-priority (concurrent)
1971 start_wqthread
1971 _pthread_wqthread
1971 _dispatch_worker_thread2
1971 _dispatch_call_block_and_release
1971 ____NSOQSchedule_block_invoke_2
1971 -[__NSOperationInternal start]
1971 -[NSInvocationOperation main]
1971 -[NSInvocation invoke]
1971 __invoking___
1971 0x17a64
1971 0x244cf
1971 0x22a97
1971 -[NSImage CGImageForProposedRect:context:hints:]
1971 -[NSImage _usingBestRepresentationForRect:context:hints:body:]
1971 __-[NSImage CGImageForProposedRect:context:hints:]_block_invoke_1
1971 -[NSImage _snapshotRepForRep:rect:context:processedHints:]
1971 -[NSImage _createSnapshotRepForRep:rect:context:processedHints:]
1971 -[NSImageRep CGImageForProposedRect:context:hints:flipped:]
1971 -[NSIconRefImageRep CGImageForProposedRect:context:hints:]
1971 _ISCreateCGImageForType
1971 _ISGetCGImageRefForISImageRef
1971 _ISImageRefIterator(void*, unsigned char, short (*)(void*, void*), void*)
1971 _ISGoThruImageStorages
1971 MergeBestStorageIntoContext(void*, void*)
1971 _CFRelease
1971 image_finalize
1971 _CFRelease
1971 image_provider_finalize
1971 ImageProviderReleaseInfoCallback
1971 __spin_lock
1971 Thread_1019 DispatchQueue_6: com.apple.root.default-priority (concurrent)
1971 start_wqthread
1971 _pthread_wqthread
1971 _dispatch_worker_thread2
1971 _dispatch_call_block_and_release
1971 ____NSOQSchedule_block_invoke_2
1971 -[__NSOperationInternal start]
1971 NSPopAutoreleasePool
1971 _CFAutoreleasePoolPop
1971 CFRelease
1971 -[NSImage dealloc]
1971 -[NSImage _deallocAuxiliaryStorage]
1971 -[NSCGImageSnapshotRep dealloc]
1971 _CFRelease
1971 image_finalize
1971 _CFRelease
1971 image_provider_finalize
1971 ImageProviderReleaseInfoCallback
1971 __spin_lock
1971 Thread_1031
1971 thread_start
1971 _pthread_start
1971 startIOThread(void*)
1971 CVDisplayLink::runIOThread()
1971 pthread_cond_wait$UNIX2003
1971 _pthread_cond_wait
1971 __semwait_signal
Total number in stack (recursive counted multiple, when >=5):
17 _CFRelease
6 ImageProviderReleaseInfoCallback
6 image_finalize
6 image_provider_finalize
5 __spin_lock
5 _dispatch_worker_thread2
5 _pthread_wqthread
5 start_wqthread
Sort by top of stack, same collapsed (when >= 5):
__spin_lock 9855
__semwait_signal 1971
kevent 1971