虽然视频捕获工作正常,但是当收到视频样本时,会有累积的内存泄漏,当没有接收到视频样本时(只有音频),没有泄漏(内存消耗停止增长)
我正在混合Cocoa线程和POSIX线程,我确保将[NSThread isMultiThreaded]设置为YES(通过创建一个空的NSThread)
" Obj-C Auto Ref Counting"在项目属性中设置为YES
以下是导致泄密的代码的简短代码 - 快照:
OSStatus status = 0;
@autoreleasepool {
m_udid = udid;
if (0 != (status = Utils::CoreMediaIO::FindDeviceByUDID(m_udid, m_devId)))
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
if (0 != (status = Utils::CoreMediaIO::GetStreamByIndex(m_devId, kCMIODevicePropertyScopeInput, 0, m_strmID)))
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
status = Utils::CoreMediaIO::SetPtopertyData(m_devId, kCMIODevicePropertyExcludeNonDALAccess, 1U);
status = Utils::CoreMediaIO::SetPtopertyData<int>(m_devId, kCMIODevicePropertyDeviceMaster, getpid());// Exclusive access for the calling process
// Results in an infinitely accumulating memory leak
status = CMIOStreamCopyBufferQueue(m_strmID, [](CMIOStreamID streamID, void* token, void* refCon) {
@autoreleasepool {
CMSampleBufferRef sampleBuffer;
while(0 != (sampleBuffer = (CMSampleBufferRef)CMSimpleQueueDequeue(m_queueRef))) {
CFRelease(sampleBuffer);
sampleBuffer = 0;
}
}
}, this, &m_queueRef);
if(noErr != status)
return E_FAIL;
if(noErr != (status = CMIODeviceStartStream(m_devId, m_strmID)))
return E_FAIL;
}
在主线程中完成了样本排队(使用&#39; dispatch_async(dispatch_get_main_queue(),^ {&#39;)没有任何影响......
以上代码快照有什么问题吗?这可能是OS Bug吗?
参考链接:https://forums.developer.apple.com/message/46752#46752
QuickTime播放器支持使用iOS设备作为捕获源(将其镜像到Mac机器的A / V),预览会话运行一段时间再现上述问题w / OS提供的QuickTime播放器,这强烈表明操作系统Bug,下面是一个屏幕截图,显示QT播放器在运行〜 2 小时后开始 140Mb 的RAM(其中它开始于 20Mb ),到那天结束时它已经增长到 ~760Mb ......
APPLE请将此修复,我有客户的承诺......