English 中文(简体)
JQuery 标签在 Firefox 扩展名中创建内存泄漏
原标题:JQuery Tabs creating memory leak in Firefox extension

I am using jQuery tab library in my Firefox extension. Tabs feature is working fine in my extension. However it is creating a zombie compartment.

这就是我如何使用标签:

$j(mydiv).find( #targetid ).tabs({selected: 2});

当我评论这条线并安装扩展名时,没有内存泄漏。知道发生了什么吗?

问题回答

问题在于 jQuery 界面存在于浏览器窗口中, 只要浏览器窗口保持打开, 就会保持“ 流动 ” 。 然而, 标签在内容标签中, 一旦您关闭标签, 标签就会消失。 jQuery 界面必须保存标签在某个地方的本地引用, 而引用不会让标签在标签关闭后收集垃圾( 僵尸隔间 ) 。 一种解决办法是找到该引用并删除它。 但是即使你这样解决它( 我无法做到, 因为不知道 jQuery ), 问题可能会在稍后出现, 因为 jQuery 界面是设计在一个网页上运行的, 这种记忆泄漏会被考虑进去 。

更稳健的解决方案是运行 jQuery 界面, 与它负责的 UI 相同。 这样, 您关闭 JQuery 界面及其部件的标签时, 将会被处理 - 不再有僵尸隔间 。 您可以使用 < a href=" https:// developmenter.mozilla. org/ en/ The_ messesage_manager" rel=“ nofollow” >Message 管理器 来完成 :

// Load content script into the current tab
var contentScriptURL = "chrome://.../content/contentScript.js";
gBrowser.selectedBrowser.messageManager.loadFrameScript(contentScriptURL, false);

contentScript.js 然后使用mozIJSSubSpript Loader ,将jQuery和jQuery UI装入上下文:

var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
                     .getService(Components.interfaces.mozIJSSubScriptLoader);
scriptLoader.loadSubScript("chrome://.../content/jquery.js");
var jQuery = jQuery.noConflict(true);
scriptLoader.loadSubScript("chrome://.../content/jquery-ui.js", jQuery);
...
$j(mydiv).find( #targetid ).tabs({selected: 2});

此内容脚本拥有与您上铺操作的脚本相同的铬特权, 但一旦标签关闭, 将会卸载它, 并加上任何引用, 它可能会保存到标签的内容 。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签