如何清理 RedLaser SDK 中 BarcodePickerController:viewWillAppear 中创建的 AVCaptureSessions?

发布于 2024-10-25 09:38:46 字数 1335 浏览 1 评论 0原文

使用分配性能工具进行的调查显示,AVCaptureSessions 正在被分配,并且从未在 RedLaser SDK 中的 BarcodePickerController:viewWillAppear 中释放。

BarcodePickerController *_barcodeScanner = [[BarcodePickerController alloc] init];

[_barcodeScanner viewDidLoad];

//[_barcodeScanner viewWillAppear:NO]; // Option 1.
//[_barcodeScanner viewDidAppear:NO]; // Option 1.

[_barcodeScanner stopScanning];

for (int i = 0; i < 200; i++) {
    NSLog(@"Run:%d", i);
    //[_barcodeScanner resumeScanning]; // Option 1.
    //[_barcodeScanner stopScanning]; // Option 1.

    [_barcodeScanner viewWillAppear:NO]; // Option 2.
    [_barcodeScanner viewDidAppear:NO];  // Option 2.
    [_barcodeScanner viewWillDisappear:NO]; // Option 2.
    [_barcodeScanner viewDidDisappear:NO]; // Option 2.
}

//[_barcodeScanner viewWillDisappear:NO]; // Option 1.
//[_barcodeScanner viewDidDisappear:NO]; // Option 1.

[_barcodeScanner viewDidUnload];

[_barcodeScanner release];

背景是我正在编写一个带有两个 AVCaptureSession 的应用程序。一个是由红色激光创建和管理的,如上面的示例代码所示,另一个是我自己手动创建的。我需要使用上面代码中所示的选项 2 而不是选项 1 来解决另一个错误,即自动对焦在第二个创建的捕获会话中停止工作(无论是我的激光还是红色激光)。

我发现的针对自动对焦错误的唯一解决方法是完全重新创建捕获会话,而不仅仅是启动和停止它们。我可以使用红色激光 sdk 来执行此操作,如上面的选项 2 所示,但这最终会导致我的应用程序在会话之间经过一定次数的转换并收到内存警告后被终止。发生这种情况是因为 AVCaptureSessions 没有被清理。

使用选项 1 时,我没有任何内存警告或泄漏。

如何清理这些任性的 AVCaptureSession?

Investigation with the allocations performance tool shows that AVCaptureSessions are being allocated and never released in BarcodePickerController:viewWillAppear in the RedLaser SDK.

BarcodePickerController *_barcodeScanner = [[BarcodePickerController alloc] init];

[_barcodeScanner viewDidLoad];

//[_barcodeScanner viewWillAppear:NO]; // Option 1.
//[_barcodeScanner viewDidAppear:NO]; // Option 1.

[_barcodeScanner stopScanning];

for (int i = 0; i < 200; i++) {
    NSLog(@"Run:%d", i);
    //[_barcodeScanner resumeScanning]; // Option 1.
    //[_barcodeScanner stopScanning]; // Option 1.

    [_barcodeScanner viewWillAppear:NO]; // Option 2.
    [_barcodeScanner viewDidAppear:NO];  // Option 2.
    [_barcodeScanner viewWillDisappear:NO]; // Option 2.
    [_barcodeScanner viewDidDisappear:NO]; // Option 2.
}

//[_barcodeScanner viewWillDisappear:NO]; // Option 1.
//[_barcodeScanner viewDidDisappear:NO]; // Option 1.

[_barcodeScanner viewDidUnload];

[_barcodeScanner release];

The background is that I am writing an application with two AVCaptureSessions. One is created and managed by red laser as shown in the above sample code while the other is created by myself manually. I need to use option 2 as shown in the above code rather than option 1 to work around another bug where autofocus stops working in the capture session that is created second (be it my one or red lasers).

The only work around I have found for the autofocus bug is to recreate the capture sessions entirely rather than just starting and stopping them. I can do this with the red laser sdk as shown in option 2 above, but this eventually leads to my app being killed after a certain number of transitions between the sessions and receiving memory warnings. This occurs due to the fact that the AVCaptureSessions are not being cleaned up.

I don't have any memory warnings or leaks when using option 1.

How can these wayward AVCaptureSessions be cleaned up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2024-11-01 09:38:46

RedLaser 技术支持已确认这是其 SDK 2.X 中的错误。他们的技术支持和我本人已经确认该错误已在 SDK 版本 3 中修复。

RedLaser technical support have confirmed that this is a bug in their SDK 2.X. Their technical support and myself have confirmed that the bug is fixed in version 3 of the SDK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文