iOS Safari内存泄漏导致应用程序无法使用
iOS Safari memory leak makes Apps unusable
我的web应用程序中有一个"可编辑表"。它的工作原理是,当你点击表的td时,我读取td的innerHTML,并生成一个输入字段,我用innerHTML的值将其注入td。
当您模糊/聚焦输入字段时,我会破坏输入字段并设置新值的innerHTML,并发送AJAX请求来更新该字段。这在台式机和安卓手机上非常适用,但在iOS Safari上,你编辑的值越多,速度就会越来越慢。经过大约250次编辑后,滚动将变得非常不稳定,最终页面将变得几乎不可用。页面刷新并不能解决问题,它要求您完全关闭网页并重新开始。
这让我相信Safari并没有释放被破坏的输入字段的内存。
下面给出了相关的JavaScript代码,点击td:即可启动
_handleEditing: function($td) {
var value = $td.find("span").html().replace(",", ""),
ctrl = this;
$td.unbind('click');
// Clone the input control
var $editControl = $('#input .edit-control').clone();
if(this.isMobile) {
$editControl.attr('type', 'number');
$editControl.attr('step', '0.01');
}
// Inject editControl into td html and set appropriate values
$td.html($editControl);
$editControl.val(value);
// Focus the edit control and set the selection range
$editControl.focus();
setTimeout(function() {
$editControl.get(0).setSelectionRange(0, value.length);
}, 0);
firstKeydown = true;
// Handle leaving the input field and returning to normal number
$editControl.on('blur', function(){
var newValue = $editControl.val();
// If the newValue is empty, go back to the old value
newValue = (newValue === '') ? value : newValue;
var parsedNewValue = parseFloat(newValue).toFixed(2);
// If the newValue is not actually a number, go back to the old value
newValue = isFinite(parsedNewValue) ? parsedNewValue : value;
$editControl.unbind().remove();
$editControl = null;
$td.html("<span>"+newValue+"</span>");
// Queue this value update to server
if(parseFloat(newValue) !== parseFloat(value)) {
ctrl.handleValueChanged($td, value, newValue);
}
// Reinstate the click handler on the td
$td.click(function(){
ctrl._handleEditing($td);
});
});
this._attachNavigationHandlers($editControl);
},
任何帮助都将不胜感激。苹果开发者请帮助
根据我对类似问题所做的研究(iOS上的性能逐渐下降),我发现了许多来源表明这是iOS本身的问题。
iOS 9中的性能问题似乎与Safari中的一个错误有关。无论您使用的是Safari、UIWebView还是WKWebView。。。每次选择文本输入字段时,您都会注意到性能的提高。我创建了一个包含100个文本输入的基本html页面。。。当我浏览输入几次时,应用程序最终对手势没有反应。Webview/Webkit中唯一的解决方案(据我所知)是重新启动应用程序。
参考:https://forums.developer.apple.com/thread/21956
到目前为止,似乎还没有解决方案。在我的情况下,当用户注销时,我会强制关闭应用程序。不幸的是,如果你想让你的应用程序出现在应用商店中,你无法通过编程退出你的应用。
- React/redux应用程序在Safari上呈现空白屏幕
- 在Chrome和Safari中启动Angular JS应用程序的差异
- 带有RequireJS的AngularJS应用程序在Safari和Firefox中给出了“使用严格”错误
- window.open()没有'无法在添加到主屏幕的移动Safari web应用程序中工作
- 如何阻止iPhone web应用程序链接在Safari中打开
- Safari-->"应用程序缓存清单的MIME类型不正确:text/plain&”;
- 在ipod上的safari浏览器中运行asp.net应用程序
- Mobile Safari是否清理DOM应用程序缓存?何时清理
- Web 应用程序在 Safari 中打开链接,而不是在现有视图中打开链接
- Ext js 4.2.3 beta - Safari 上的离线应用程序区域设置
- 应用程序缓存清单在Firefox中未加载,在Chrome和Safari中正常
- 从 Safari 调用 iOS 安装的应用程序
- iPad 网络应用程序在 Safari 中打开链接后冻结
- 从Safari iPad中的html5 web应用程序上传音频文件
- iOS Safari内存泄漏导致应用程序无法使用
- 支持苹果移动网络应用程序的faq链接在safari开放
- 当我制作一个网络应用程序时,如何在safari中禁用复制、过去、选择、全选
- 如何在Safari中打开外部链接而不是应用程序'的UIWebView
- 在移动Safari上预加载HTML5应用程序的图像
- 移动Safari/Chrome上Angular应用程序的键盘严重滞后