2

UI がメイン ページで処理され、コントローラーとモデルが非表示のフレームに読み込まれる 1 ページ アプリがあります。ある時点で、これらのモデルとコントローラーを変更する必要があるため、フレームを削除し、別のコントローラーとモデルを使用して新しいフレームを作成し、メイン ページの UI を制御できるようにします。

問題は、フレームが DOM から削除されると、フレーム内で実行されていた JS がメモリからクリアされるのか、それともメモリ リークの可能性があるのか​​ということです。

4

2 に答える 2

3

So the question is, does the JS that was running inside of the frame gets cleared from the memory once the frame is removed from the DOM or am I looking at potential memory leak?

The JS and such in the frame are eligible to be removed from memory when the last outstanding reference to them is released. So you could remove the frame from the DOM, but if you still have a reference to it (for instance, in a JavaScript variable in another frame/window), then it will remain in memory. Or if you still have variables in another frame/window that refer to objects created in the frame you're removing, they (but not necessarily the frame) will be kept.

If you don't have any variables left pointing at the frame or the things in it, and you remove it from the DOM, then it will be eligible for garbage collection. When that happens is browser-dependent, but it will happen.

于 2013-05-06T18:18:40.867 に答える
2

ブラウザはメモリ使用量を管理します。JavaScript によって作成されたメモリ リークは、事実上、特にあなたが説明したような状況では、ブラウザ自体の欠陥です。JavaScript で「メモリ リーク」に最も近いのは、使用し続けないグローバル スコープでオブジェクトをインスタンス化することです。これは、実行時間の長いページ (GMail の動的 Web アプリなど) にのみ影響します。

于 2013-05-06T18:15:17.363 に答える