发布IOSurface [英] Releasing an IOSurface
问题描述
此问题扩展为:
Link-1:从ios表面创建并保存图像
Link-2:从iOS应用程序获取屏幕截图 - 模拟显示记录器(内部查询)
(参考链接-1)我有在后台工作时截取屏幕截图的代码。但如上所述,它需要2秒的睡眠才能不间断地工作,否则操作系统会暂停应用程序。我想出原因可能是我没有明确发布我创建的IOSurface。
原因 - 使用链接 http://pastie.org/pastes/3734430由Victor Ronin给出的,即使没有睡眠,捕获也能正常工作。
我尝试在每次写入图像后使用CFRelease释放destSurf(我创建的目标表面),但这不起作用。
(Refer Link-1) I have the code for taking screenshots in the background working. But as stated, it requires a sleep of 2 sec to work uninterruptedly, otherwise the OS suspends the app. I figured out the reason could be that I am not explicitly releasing the IOSurface I create.
Reason - Using the link http://pastie.org/pastes/3734430 given by Victor Ronin, the capture works fine even without the sleep.
I tried releasing the destSurf (destination surface that I have created) using CFRelease after I write the image each time, but that doesn't work.
任何帮助何时,如何以及是否发布创建的IOSurface,将非常有用。谢谢。
更新
所以,这就是确切发生的事情。 (参考链接-1)
Any help on when, how and whether or not to release a created IOSurface, will be really useful. Thanks.
Update
So, this is what exactly happens. (Referring Link-1)
IOSurfaceRef destSurf = IOSurfaceCreate(dict);
IOSurfaceAcceleratorRef outAcc;
IOSurfaceAcceleratorCreate(NULL, 0, &outAcc);
CFDictionaryRef ed = (__bridge CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: nil];
IOSurfaceAcceleratorTransferSurface(outAcc, screenSurface, destSurf, ed, NULL);
IOSurfaceUnlock(screenSurface, kIOSurfaceLockReadOnly, &aseed);
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, IOSurfaceGetBaseAddress(destSurf), (width*height*4), NULL);
CGImageRef cgImage=CGImageCreate(width, height, 8, 8*4, IOSurfaceGetBytesPerRow(destSurf), CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, provider, NULL, YES, kCGRenderingIntentDefault);
UIImage *image = [UIImage imageWithCGImage: cgImage];
CGImageRelease(cgImage);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
CFRelease(destSurf);
- 调用CFRelease并发生应用程序崩溃。没有保存图像。但是,如果您在发布前1-2秒进行睡眠,则可以正常工作。
- 如果你跳过对UIImageWriteToSavePhotosAlbum()的调用,一切正常,捕获不会中断。
我仍然不清楚究竟是什么问题以及如何解决问题。任何帮助都非常感谢。
推荐答案
我认为你需要释放表面。它由API IOSurfaceCreate创建,不受autorelease的管理。
I think you need to release surface. It's create by API IOSurfaceCreate which isn't managed by autorelease's.
作为示例,我发现以下代码已经发布:
As example I found following code where it's released:
会发生什么如果你试图用CFRelease释放它?它会崩溃还是有相同的2秒问题?
What happens if you try to release it with CFRelease? Does it crash or does it have the same 2 secs problem?
这篇关于发布IOSurface的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!