科尔多瓦打开和关闭一个新窗口

时间:2014-09-02 16:26:40

标签: jquery-mobile cordova memory-leaks mobile-safari webpage

Safari中存在内存泄漏导致我的cordova应用程序出现问题。我正在使用WebAudio Api,似乎浏览器没有正确处理垃圾收集。经过多次调查后,我发现有人遇到类似的问题并且他们的解决方案是在iframe中播放/录制声音,然后销毁iframe。 https://github.com/CreateJS/SoundJS/issues/102

I have successfully found a fix for this issue, and it's a hacky one :+1:

So after some experimentation , I discovered this bug is due to mobile safari, not soundjs. Whilst disabling sounds on ipad for our webapp (to prevent memory leaks and the eventual crash), I accidentally discovered that sounds created in an iframe were being correctly cleaned up.

The solution is simple, whenever a sound is played, create it in a script within an iframe. When you are done, destroy that iframe. I changed my old test to confirm this (the old one crashed at 34 plays):

http://files.dubitlimited.com/sjsiframetest/

然而,在我的解决方案中,我使用一些本机功能(我需要访问文件系统以获取其中一个声音)以及一些WebAudio Api功能。我想要做的是打开iframe,访问文件系统,将我的两个录音混合在一起,将它们保存到文件系统,然后删除iframe。这有望克服我的内存泄漏。几周前我确实设法对它进行了测试,并设法让它发挥作用,但不能为我的生活记住如何。

现在当我回到它时,我在新创建的iframe上初始化应用时遇到了问题。如果没有初始化应用程序,我无法访问任何Cordova功能,例如LocalFileSystem'。每当我尝试在iframe中初始化应用程序时,我都会收到错误 deviceready在5之后没有被解雇 秒

我还试图单独加载html页面<a href="record.html" data-ajax="false">RECORD</a>,但我似乎也无法初始化该页面。

记录html页面如下所示:

    <!DOCTYPE html>
<html>
<head>
    <title>Record</title>
</head>

<body onload="createAudioContext();">
Test Iframe
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/ici_pici.js"></script>
<script> app.initialize();</script>
</body>
</html>

据我所知,建议使用单页应用,因此尝试加载单独的页面是违反最佳做法的,但我需要克服此内存泄漏,而我能看到的唯一方法是从窗口调用函数,我可以在以后销毁。

关于我如何处理此事的任何建议?

由于

0 个答案:

没有答案
相关问题