我有一个使用phonegap-plugin-barcodescanner(v 6.0.1)的cordova(目前为5.3.3)项目。最近我遇到了我认为在iOS 10中存在某种大内存泄漏的情况。当应用程序在iOS 10上运行时,它似乎永远不会释放与扫描程序相关的资源。但是在iOS 7或9上,一切正常。这可以在内存报告中看到。
iOS 10
iOS 7
我试图使用仪器中的泄漏检查器来追踪泄漏,但我似乎无法在测试中找到任何实质内容。我使用该工具找到的每个扫描大约有1KB的泄漏对象。
我想我的主要问题是,是否有更好的方法来追踪似乎与此扫描仪绑定的内存问题?在iOS 10中发生重新分配/引用计数的方式是否会发生某种变化会导致如此剧烈的变化?
我已经使用上面提到的插件创建了一个准系统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>
编辑:经过进一步调查后,我注意到VM中似乎有一个相当大的IOKit分配,我不知道它来自哪里。你可以在VM摘要中看到,iPad没有分配这100个MiB块,但是在iOS 10中这样做了。我还不确定它来自何处或是什么会强制这些额外的调用
iOS 10
iOS 7
答案 0 :(得分:0)
我有同样的问题,但我现在解决了。只需用以下https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/src/ios/CDVBarcodeScanner.mm
替换您的插件文件CDVBarcodeScanner.mm即可答案 1 :(得分:0)
在对github和进一步调查进行一些讨论后,我发现问题是由使用AVCaptureVideoDataOutputSampleBufferDelegate的插件引起的。看来视频输出设置导致IOKit级别的一些泄漏。
对此的解决方案是更新插件以使用AVCaptureMetadataOutputObjectsDelegate并更新输出以使用AVCaptureMetadataOutput类型。这需要实现方法(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]];
}
这些提到的更改是作为插件v 6.0.3的一部分发布的。