Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅在iOS 10中扫描仪插件内存泄漏_Ios_Objective C_Cordova_Cordova Plugins_Ios10 - Fatal编程技术网

仅在iOS 10中扫描仪插件内存泄漏

仅在iOS 10中扫描仪插件内存泄漏,ios,objective-c,cordova,cordova-plugins,ios10,Ios,Objective C,Cordova,Cordova Plugins,Ios10,我有一个cordova(目前为5.3.3)项目,它使用(v6.0.1)。最近我遇到了一个我认为是IOS10中某种类型的大内存泄漏。当应用程序在iOS 10上运行时,它似乎从未释放绑定到扫描仪的资源。然而,在iOS 7或9上,一切正常。这可以在下面的内存报告中看到 iOS 10 iOS 7 我曾尝试在仪器中使用检漏仪跟踪泄漏,但在测试中似乎找不到任何实质性的东西。使用该工具,我只能在每次扫描中发现大约1KB的泄漏物体 我想我的主要问题是,有没有更好的方法来跟踪与此扫描仪相关的内存问题?iOS

我有一个cordova(目前为5.3.3)项目,它使用(v6.0.1)。最近我遇到了一个我认为是IOS10中某种类型的大内存泄漏。当应用程序在iOS 10上运行时,它似乎从未释放绑定到扫描仪的资源。然而,在iOS 7或9上,一切正常。这可以在下面的内存报告中看到

iOS 10

iOS 7

我曾尝试在仪器中使用检漏仪跟踪泄漏,但在测试中似乎找不到任何实质性的东西。使用该工具,我只能在每次扫描中发现大约1KB的泄漏物体

我想我的主要问题是,有没有更好的方法来跟踪与此扫描仪相关的内存问题?iOS 10中释放/引用计数的方式是否发生了某种变化,从而导致如此剧烈的变化

我已经用上面提到的插件创建了一个barebones cordova项目,并实现了一个对按钮的基本扫描调用,如代码所示,它应该提供一个可复制的测试

<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
    <!--
    Customize this policy to fit your own app's needs. For more guidance, see:
        https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
    Some notes:
        * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
        * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
        * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
            * Enable inline JS: add 'unsafe-inline' to default-src
    -->

    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <title>Hello World</title>
</head>
<body>
    <div class="app">
        <script type="text/javascript">
            function scanTest(field) {
                try {
                    debugger
                    var scanner = window.cordova.require("phonegap-plugin-barcodescanner.BarcodeScanner");
                    scanner.scan(
                                 function (result) {
                                 if (document.getElementById(field)) {
                                 document.getElementById(field).innerHTML = result.text;
                                 } else {
                                 alert("ScannerCouldntIdentifyMessage");
                                 }
                                 });
                } catch (e) {
                    alert("ErrorDescription: " + e);
                }
            }
        </script>
        <h1>Apache Cordova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
            <p id="scan">Test scan</p>
            <a href="#" onclick="scanTest('scan')" id="scantest">Scan</a>
        </div>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</body>
</html>

你好,世界
功能扫描测试(现场){
试一试{
调试器
var scanner=window.cordova.require(“phonegap插件barcodescanner.barcodescanner”);
扫描器(
功能(结果){
if(document.getElementById(字段)){
document.getElementById(field).innerHTML=result.text;
}否则{
警报(“扫描者无法识别信息”);
}
});
}捕获(e){
警报(“错误描述:”+e);
}
}
阿帕奇科尔多瓦酒店
连接到设备

设备已准备就绪

测试扫描

编辑:经过进一步调查,我注意到虚拟机中似乎有一个相当大的IOKit分配,我不确定它来自哪里。从VM摘要中可以看出,iPad没有分配这100个MiB块,而是在iOS 10中分配。我仍然不确定这是从哪里来的,或者是什么会迫使这些额外的电话

iOS 10

iOS 7
我也有同样的问题,但我现在解决了。只需将您的插件文件CDVBarcodeScanner.mm替换为以下内容

我也遇到过同样的问题,但我现在已经解决了。只需将您的插件文件CDVBarcodeScanner.mm替换为以下文件

在对github进行了一些讨论和进一步调查后,我发现问题是由使用AVCaptureVideoDataOutputSampleBufferDelegate的插件引起的。视频输出设置似乎导致IOKit级别出现一些泄漏

解决方法是更新插件以使用AvCaptureMataOutputObjectsDelegate,并更新输出以使用AvCaptureMataOutput类型。这需要实现方法
(void)captureOutput:(AVCaptureOutput*)captureOutput didOutputMetadataObjects:(NSArray*)metadataObjects fromConnection:(AVCaptureConnection*)connection

此方法与前一种方法非常相似,但不是使用zxing库进行解码,而是使用循环和AVMetadata类进行解码:

  for (AVMetadataObject *metaData in metadataObjects) {
    AVMetadataMachineReadableCodeObject* code = (AVMetadataMachineReadableCodeObject*)
[self.previewLayer transformedMetadataObjectForMetadataObject:
(AVMetadataMachineReadableCodeObject*)metaData];

  if ([self checkResult:code.stringValue]) {
    [self barcodeScanSucceeded:code.stringValue format:[self formatStringFromMetadata:code]];
  }

这些提到的更改是作为插件v6.0.3的一部分发布的。

在对github进行了一些讨论和进一步调查后,我发现问题是由使用AVCaptureVideoDataOutputSampleBufferDelegate的插件引起的。视频输出设置似乎导致IOKit级别出现一些泄漏

解决方法是更新插件以使用AvCaptureMataOutputObjectsDelegate,并更新输出以使用AvCaptureMataOutput类型。这需要实现方法
(void)captureOutput:(AVCaptureOutput*)captureOutput didOutputMetadataObjects:(NSArray*)metadataObjects fromConnection:(AVCaptureConnection*)connection

此方法与前一种方法非常相似,但不是使用zxing库进行解码,而是使用循环和AVMetadata类进行解码:

  for (AVMetadataObject *metaData in metadataObjects) {
    AVMetadataMachineReadableCodeObject* code = (AVMetadataMachineReadableCodeObject*)
[self.previewLayer transformedMetadataObjectForMetadataObject:
(AVMetadataMachineReadableCodeObject*)metaData];

  if ([self checkResult:code.stringValue]) {
    [self barcodeScanSucceeded:code.stringValue format:[self formatStringFromMetadata:code]];
  }

这些提到的更改是作为插件版本6.0.3的一部分发布的。

尽管总是欢迎指向潜在解决方案的链接,但堆栈溢出问题的答案应该始终在答案正文中包含解决方案的主要部分/要点。仅仅链接到一个解决方案而没有进一步的评论,被认为是不可接受的答案。请参阅如何制定正确的答案。虽然始终欢迎指向潜在解决方案的链接,但有关堆栈溢出的答案应始终在答案正文中包含解决方案的主要部分/要点。仅仅链接到一个解决方案而没有进一步的评论,被认为是不可接受的答案。请参阅如何制定正确答案。