【问题标题】:getImageData memory leak issue in window's chrome browser : javascriptWindows chrome 浏览器中的 getImageData 内存泄漏问题:javascript
【发布时间】:2016-06-15 02:21:23
【问题描述】:

当在 Window 7 的 chrome 浏览器中循环使用从画布中获取数据时,我在 getImageData()[api 提供的 javascript] 上遇到内存泄漏问题,它会在 getImageData() api 上的每次旅行中增加 chrome 内存,所以一段时间后,默认 chrome 内存已满,如果有人知道任何解决方法,请提出建议。

使用的代码:

this.surface.drawImage(this.st1, 0, 0, this.canvas.width, this.canvas.height); 
var data = this.surface.getImageData(0,0, this.canvas.width, 
this.canvas.height);
this.timer = setTimeout(this.paint, 500);

【问题讨论】:

    标签: javascript google-chrome google-chrome-app


    【解决方案1】:

    this 属于调用它的方法的owner

    setTimeout中,this属于窗口,因为setTimeoutwindow的方法=>window.setTimeout

    使用.bind()

    试试这个:

    this.surface.drawImage(this.st1, 0, 0, this.canvas.width, this.canvas.height); 
    var data = this.surface.getImageData(0,0, this.canvas.width, 
    this.canvas.height);
    this.timer = setTimeout(paint.bind(this), 500);

    【讨论】:

    • 试过(.bind())你的解决方案,但它仍然不断增加 chrome 内存:不工作请建议我是否缺少任何东西。
    • 也是你创建 var _this=this 的原因;但你没有使用它。
    • 你能分享你在画布上绘制的图像文件的尺寸吗?
    • 画布:宽度:1024 高度:786,maxFrameRate:25
    • 请参考此示例并单击顶部按钮执行:jsfiddle.net/dvu9z6td 所以仅供参考的问题仅在窗口 7 chrome 浏览器上
    猜你喜欢
    • 2015-07-12
    • 2011-03-08
    • 2011-11-30
    • 2011-07-08
    • 1970-01-01
    • 2012-01-13
    • 2011-09-22
    • 2014-06-07
    • 2012-12-19
    相关资源
    最近更新 更多