9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[WebRTC] new RTCPeerConnection()を何回も呼ぶとメモリリークする

Last updated at Posted at 2016-01-11

以下のコードは少なくともChrome 47とFirefox 43でメモリリークを起こすようだ。

var RTCPeerConnection = window.RTCPeerConnection
    || window.mozRTCPeerConnection
    || window.webkitRTCPeerConnection;
while (true) {
    var pc = new RTCPeerConnection({});
    pc.close();
}

JSFiddleによる実行例(注意: リンク先に飛ぶとブラウザがクラッシュする)

自分の最新のIPアドレスを取得するためにwebrtc-ipsをポーリングしようとしたのだが、メモリ使用量がどんどん増えていくので気付いた。

対処法

  • そもそもnew RTCPeerConnection()を大量に呼ぶコードを書かない
  • 大量に呼ぶ必要がある場合は、適当なときにlocation.reload()する
9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?