jQuery:加载图像时主内存过高

时间:2015-01-28 13:45:39

标签: javascript jquery ajax memory-leaks

我的网络应用使用AJAX显示直播。事实上,我们使用jquery每50毫秒从服务器加载一个新图像。 问题是,只要启动直播,浏览器(谷歌浏览器)就需要增加主内存。这持续约20分钟,然后系统滞后,浏览器消耗的RAM超过1GB。

以下代码用于将服务器中的图像加载到html元素中:

img = $( defaultWebcamHtml ).attr('src', urlImage + new Date().getTime() + imageExtension)
        .load(function() {
            if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
                console.log('[Error] Broken image!');
            } else {
                if(!(img === null)) {
                    $(htmlImgId).replaceWith(img); // if you comment this line out the problem seems to stop
                }
            }
            isLoading = false;
        });

该错误似乎发生在Google Chrome和Firefox中,但不是IE。

0 个答案:

没有答案